Difference between revisions of "Docker"

(Created page with "Docker is a containerization platform which packages your application and all its dependencies together in the form of containers so as to ensure that your application works s...")
 
Line 1: Line 1:
 +
=Get started with Docker for Mac=
 +
==Check versions==
 +
Ensure your versions of docker, docker-compose, and docker-machine are up-to-date and compatible with Docker.app. Your output may differ if you are running different versions.
 +
<source>
 +
$ docker --version
 +
Docker version 18.03, build c97c6d6
 +
 +
$ docker-compose --version
 +
docker-compose version 1.22.0, build 8dd22a9
 +
 +
$ docker-machine --version
 +
docker-machine version 0.14.0, build 9ba6da9
 +
</source>
 +
==Explore the application==
 +
*Open a command-line terminal and test that your installation works by running the simple Docker image, hello-world:
 +
<source>
 +
$ docker run hello-world
 +
 +
Unable to find image 'hello-world:latest' locally
 +
latest: Pulling from library/hello-world
 +
ca4f61b1923c: Pull complete
 +
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
 +
Status: Downloaded newer image for hello-world:latest
 +
 +
Hello from Docker!
 +
This message shows that your installation appears to be working correctly.
 +
...
 +
</source>
 +
 +
*Start a Dockerized web server. Like the hello-world image above, if the image is not found locally, Docker pulls it from Docker Hub.
 +
<source>
 +
$ docker run -d -p 80:80 --name webserver nginx
 +
</source>
 +
*In a web browser, go to '''http://localhost/''' to view the nginx homepage. Because we specified the default HTTP port, it isn’t necessary to append :80 at the end of the URL.
 +
 +
https://docs.docker.com/docker-for-mac/images/hello-world-nginx.png
 +
 +
'''Note:''' Early beta releases used docker as the hostname to build the URL. Now, ports are exposed on the private IP addresses of the VM and forwarded to localhost with no other host name set.
 +
 +
*View the details on the container while your web server is running (with docker container ls or docker ps):
 +
<source>
 +
$ docker container ls
 +
CONTAINER ID  IMAGE  COMMAND                  CREATED              STATUS              PORTS                        NAMES
 +
56f433965490  nginx  "nginx -g 'daemon off"  About a minute ago  Up About a minute  0.0.0.0:80->80/tcp, 443/tcp  webserver
 +
</source>
 +
 +
*Stop and remove containers and images with the following commands. Use the “all” flag (--all or -a) to view stopped containers.
 +
<source>
 +
$ docker container ls
 +
$ docker container stop webserver
 +
$ docker container ls -a
 +
$ docker container rm webserver
 +
$ docker image ls
 +
$ docker image rm nginx
 +
</source>
 +
 +
 +
 +
 +
 +
 +
 +
 +
 
Docker is a containerization platform which packages your application and all its dependencies together in the form of containers so as to ensure that your application works seamlessly in any environment be it development or test or production.
 
Docker is a containerization platform which packages your application and all its dependencies together in the form of containers so as to ensure that your application works seamlessly in any environment be it development or test or production.
  
Line 7: Line 71:
 
Official site : https://www.docker.com/
 
Official site : https://www.docker.com/
  
 +
=Docker Pros and Cons=
 
==Docker Interview Questions & Answers==
 
==Docker Interview Questions & Answers==
  

Revision as of 23:48, 28 August 2018

Get started with Docker for Mac

Check versions

Ensure your versions of docker, docker-compose, and docker-machine are up-to-date and compatible with Docker.app. Your output may differ if you are running different versions.

$ docker --version
Docker version 18.03, build c97c6d6

$ docker-compose --version
docker-compose version 1.22.0, build 8dd22a9

$ docker-machine --version
docker-machine version 0.14.0, build 9ba6da9

Explore the application

  • Open a command-line terminal and test that your installation works by running the simple Docker image, hello-world:
$ docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
...
  • Start a Dockerized web server. Like the hello-world image above, if the image is not found locally, Docker pulls it from Docker Hub.
$ docker run -d -p 80:80 --name webserver nginx
  • In a web browser, go to http://localhost/ to view the nginx homepage. Because we specified the default HTTP port, it isn’t necessary to append :80 at the end of the URL.

hello-world-nginx.png

Note: Early beta releases used docker as the hostname to build the URL. Now, ports are exposed on the private IP addresses of the VM and forwarded to localhost with no other host name set.

  • View the details on the container while your web server is running (with docker container ls or docker ps):
$ docker container ls
CONTAINER ID   IMAGE   COMMAND                  CREATED              STATUS              PORTS                         NAMES
56f433965490   nginx   "nginx -g 'daemon off"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, 443/tcp   webserver
  • Stop and remove containers and images with the following commands. Use the “all” flag (--all or -a) to view stopped containers.
$ docker container ls
$ docker container stop webserver
$ docker container ls -a
$ docker container rm webserver
$ docker image ls
$ docker image rm nginx





Docker is a containerization platform which packages your application and all its dependencies together in the form of containers so as to ensure that your application works seamlessly in any environment be it development or test or production.

Docker containers, wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries etc. anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.

Docker Hub : https://hub.docker.com

Official site : https://www.docker.com/

Docker Pros and Cons

Docker Interview Questions & Answers

What is Docker?

Docker is a containerization platform which packages your application and all its dependencies together in the form of containers so as to ensure that your application works seamlessly in any environment be it development or test or production.

Docker containers, wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries etc. anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.

You can refer the diagram shown below, as you can see that containers run on a single machine share the same operating system kernel, they start instantly as only apps need to start as the kernel is already running and uses less RAM.

What are the differences between Docker and Hypervisors?

Docker-vs-Hypervisors-Docker-Interview-Questions-Edureka-2.png

What is Docker image?

Docker image is the source of Docker container. In other words, Docker images are used to create containers. Images are created with the build command, and they’ll produce a container when started with run. Images are stored in a Docker registry such as registry.hub.docker.com because they can become quite large, images are designed to be composed of layers of other images, allowing a minimal amount of data to be sent when transferring images over the network.

What is Docker container?

Docker containers include the application and all of its dependencies, but share the kernel with other containers, running as isolated processes in user space on the host operating system. Docker containers are not tied to any specific infrastructure: they run on any computer, on any infrastructure, and in any cloud. Now explain how to create a Docker container, Docker containers can be created by either creating a Docker image and then running it or you can use Docker images that are present on the Dockerhub.

Docker containers are basically runtime instances of Docker images.

What is Docker hub?

Docker hub is a cloud-based registry service which allows you to link to code repositories, build your images and test them, stores manually pushed images, and links to Docker cloud so you can deploy images to your hosts. It provides a centralized resource for container image discovery, distribution and change management, user and team collaboration, and workflow automation throughout the development pipeline.

How is Docker different from other container technologies?

Docker containers are easy to deploy in a cloud. It can get more applications running on the same hardware than other technologies, it makes it easy for developers to quickly create, ready-to-run containerized applications and it makes managing and deploying applications much easier. You can even share containers with your applications.

What is Docker Swarm?

Docker Swarm is native clustering for Docker. It turns a pool of Docker hosts into a single, virtual Docker host. Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.

What is Dockerfile used for?

A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

Can I use json instead of yaml for my compose file in Docker?

You can use json instead of yaml for your compose file, to use json file with compose, specify the filename to use for eg:

docker-compose -f docker-compose.json up

How to create Docker container?

We can use Docker image to create Docker container by using the below command:

docker run -t -i command name

This command will create and start a container.

You should also add, If you want to check the list of all running container with the status on a host use the below command:

docker ps -a

How to stop and restart the Docker container?

In order to stop the Docker container you can use the below command:

docker stop container ID

Now to restart the Docker container you can use:

docker restart container ID

How far do Docker containers scale?

Large web deployments like Google and Twitter, and platform providers such as Heroku and dotCloud all run on container technology, at a scale of hundreds of thousands or even millions of containers running in parallel.

What platforms does Docker run on?

Docker runs on only Linux and Cloud platforms and then I will mention the below vendors of Linux:

  • Ubuntu 12.04, 13.04 et al
  • Fedora 19/20+
  • RHEL 6.5+
  • CentOS 6+
  • Gentoo
  • ArchLinux
  • openSUSE 12.3+
  • CRUX 3.0+

Cloud:

  • Amazon EC2
  • Google Compute Engine
  • Microsoft Azure
  • Rackspace

Mention some commonly used Docker command?

Below are some commonly used Docker commands: Docker-Commands-Docker-Interview-Questions-Edureka-1.png