Step 1: Lets pull hello-world image to our
local system by executing ‘docker run hello-world’ command.
‘docker
run’ command starts a new container with the specified image.
$docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
As you see
the output, docker tries to find the ‘hello-world’ image in your computer,
since it is not available, it pulls the image from internet. Once the image is
downloaded, it ran the image and prints the output of the container ‘Hello from
Docker!’ in console.
You can
check the same by running the command ‘docker ps -a’.
$docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ecc56427245c hello-world "/hello" 3 minutes ago Exited (0) 3 minutes ago dazzling_dewdney
As you see
the output, the image ‘hello-world’ ran 3 minutes ago.
You can
get the same using ‘docker info’ command.
$docker info Containers: 1 Running: 0 Paused: 0 Stopped: 1 Images: 1 ….. …..
As you see
the output, there is 1 container that is in stopped state.
What happened internally?
When you
execute the command ‘docker run hello-world’, docker client receives this
command and calls the respective docker daemon API.
Docker
daemon checks whether the image ‘hello-world’ is available in localhost or not.
If the image is not available, then docker daemon search the image in ‘https://hub.docker.com/’
and pull the image from docker hub to local system.
Once the
image is available in local system, docker daemon starts new container with the
image.
No comments:
Post a Comment