What is Image?
- Docker Image is a package with all the dependencies and the necessary information to create the container.
- Docker Image is usually derived from multiple base images that are layers stacked on each other to form containers filesystem. Other interesting aspect is Docker Image is Immutable once its created
What is Container?
- As it already defined the earlier article container is an isolated space for execution of application. In this section we would like to look at Containers from the image perspective.
- Container is Docker Image’s instance which represents the application/service
What is Registry?
- Registry is the service which provides access to Docker Images collection.
- Docker hub is the default registry.
- Companies often prefer private repositories to store Docker Images
Referred from Microsoft Documentation
Understanding by executing a sample scenario
- Install Docker by following here
- Lets execute the following docker commands
docker images
# This command will list all the images present on the machine
- The output of the command on newly installed docker will be following
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
as the machine doesn’t have any images at this moment
- Now lets execute the command to run a container called as hello-world
docker run hello-world
# following is the output of the docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
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/
- If you observe the output of the command
docker run hello-world
there are some lines which will be important for us to understand image & registry connection
Unable to find image ‘hello-world:latest’ locally latest: Pulling from library/hello-world
- Docker is trying to search the image hello-world locally & since it doesn’t find it, it tries to do pull (download) the image from registry.
- In this case since we have not configured any specific registry, it asks the default registry Docker hub for the image with name hello-world.
- From Registry download of the image is done to the local machine. Lets verify that
docker images
# output
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest fce289e99eb9 4 weeks ago 1.84kB
- Now this image is executed to form a container. Lets verify that
docker ps -a
# output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3d6d571a19a6 hello-world "/hello" 7 minutes ago Exited (0) 7 minutes ago pensive_tereshkova
- Now lets relook into the image
Referred from Microsoft Documentation
This time it should be more convincing