Skip to content

Understand Key Concepts of Docker: Images, Layers, Containers

In the “Understand Dockerfile” article, we have explained how a Dockerfile create Docker image and docker container.

Docker Image

Docker images are read-only templates that contain instructions for creating a container. A Docker image is a blueprint of the libraries and dependencies required inside a container for an application to run.

Docker images often start with a base image, which is a minimal operating system or a specialised runtime environment. There are many popular images such as alpine, memcached, redis, nginx, python, node.

Container

A Docker container is a lightweight, standalone, and executable software package that includes everything needed to run a piece of software, including the code, runtime, libraries, and system tools.

Each container operates as an independent unit.This isolation ensures that an application and its dependencies are contained and do not interfere with other applications or the host system.

Layers

In a Docker image, the layers represent the incremental changes made during the image’s construction. Each instruction in the Dockerfile contributes to a new layer.

Base Image Layer:

The initial layer is the base image, which serves as the starting point for the Docker image. It typically contains the underlying operating system or a minimal runtime environment.

Intermediate Layers:

Each instruction in the Dockerfile, such as copying files, installing packages, or running commands, results in the creation of a new layer. These intermediate layers build upon the base image and contribute to the final configuration of the image.

Top Layers:

The top layer is the final layer, representing the state of the image after all instructions in the Dockerfile have been executed. This layer contains the application code, dependencies, and configurations.