Docker: Image vs Container – Explained

In the Docker-world there are such concepts as images, containers and layers. Despite the fact that they are closely related – they are different, and at the beginning of the Docker study, there are often difficulties in understanding these terms. This article explains the difference between images, containers and layers.

What is an Image in a Docker?

Do not Confuse: The Docker image itself can not be “run”. The command docker runtakes the Docker image as a template and creates a container from it, which is launched. Images are created from Dockerfileusing the command docker build.

Images are stored in Docker registries, such as Docker Hub and can be downloaded using the command docker pull:

To view the downloaded Docker images, run docker images:

What Are Layers in a Docker?

The images in Docker are so arranged that they consist of several layers. Each statement from Dockerfilecreates a new layer of the image. Each layer is a collection of differences (diff) from the previous layer.

To view all layers of the image, run the command docker history:

Each layer of the Docker image is read-only.

What is a Docker Container?

Main Difference: The main difference between the image and the container is in the writeable top layer.

Containers are created from images using the command docker run, and by running the command docker psyou can find out which containers are currently running.

To create a container, the Docker engine takes an image, adds a writeable top layer, and initializes various parameters (network ports, container name, identifier, and resource limits).

All write operations inside the container are stored in this top layer and when the container is deleted, the top layer that was available for writing is also deleted, while the lower layers remain unchanged.

Because each container has its own layer for writing, and all changes are stored in this layer, several containers can share access to the same basic image while remaining each in their own state.


Authored By Imran Yousaf

I am Imran Yousaf, a computer geek, founder of the site I am a die hard fond of open-source software and Linux operating system. In addition to Linux, I am interested in everything related to information technology and modern science.

Leave a Reply

Your email address will not be published. Required fields are marked *