For every programming language, we start with Hello World program. For Docker also, we will start with same. We have a hello-world instance in Docker Hub. Let’s install Docker Desktop and try pulling the image and run it.
Pulling Images from Docker Hub
Lets try pulling the image using docker pull hello-world
% docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
c9c5fd25a1bd: Pull complete
Digest: sha256:0b6a027b5cf322f09f6706c754e086a232ec1ddba835c8a15c6cb74ef0d43c29
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
We are successfully able to pull the Image into local system. Lets understand the details
tag: latest – tag is like a version. We can have multiple versions of the same Image. Default version of an Image is latest
latest: Pulling from library/hello-world – It says that the Image is pulled for Docker Registry and library/hello-world is the corresponding path where docker.io/library/hello-world:latest is the full path.
Lets see if the image is downloaded running docker image list
% docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 0b6a027b5cf3 4 months ago 17kB
As we can see, them image is there in local registry and it has the some details like name, tag(version), Id, created date, size etc. Let’s run it. To run we have to use command docker run [image_name] (docker run hello-world)
Running a Container from pulled Image
% docker run hello-world
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.
(arm64v8)
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 we can see, we have some message saying Container is running along with some additional details to understand how Docker works. If you follow the steps, now you should be able to relate the steps we discussed in Docker architecture article.
Lets explore the Container Details
Lets run docker container list -a and see the details
% docker container list -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
946d63bc4a93 hello-world "/hello" 10 minutes ago Exited (0) 5 minutes ago busy_greider
CONTAINER ID – Every Container needs to have an unique Id
IMAGE – Image name for the corresponding Container
COMMAND – Command executed immediately after Container started
CREATED – When the Container created from the Image
STATUS – Every Container has a status like it should be running or stopped. It shows the current status of the Container
PORTS – Port is used to communicate between Containers or to access any application from outside
NAMES – Every Container needs to have a name. Either we can assign a proper name or Docker daemon will assign one.
We have run multiple commands, but we need to understand them in more details along with other essential Docker commands.