hello-worldIn the previous section, we started our first container using the command.
But this raises an important question: Where does this container come from?
DockerThe answer is simple: it is created from an image.
DockerTo fully understand this, you need to keep one key concept in mind:
A container is a running instance of an image.
In other words, the image represents the template, while the container corresponds to the application that is actually running.
The construction blueprint analogy
Let’s stick with the shipyard analogy used as a guiding thread in this training.
Imagine you want to build several identical boats. To do this, you have a construction plan that serves as a reference. Using this plan, the shipyard can build as many boats as needed.
DockerIn Docker, the principle is similar:
| Real-world element | Docker |
|---|---|
| Construction plan | Image |
| Built boat | Container |
| Shipyard | Docker Engine |
A single image can therefore be used to create as many containers as needed, just as a single blueprint can be used to build multiple boats.
An image is a fixed template
An imageDockeris a read-only template. This means it cannot be modified once created. It serves as an immutable foundation used solely to launch containers.
When a container is started,Dockerit takes the image and adds a writable layer specific to the container on top of it. This layer allows the container to run, write files, or modify its environment.
Simplified diagram:
Image Docker (lecture seule)
│
▼
Couche d'écriture du conteneur
│
▼
Conteneur en fonctionnementIf the container is deleted, this writable layer disappears with it, but the image remains intact. This is why containers are considered ephemeral by default.
We’ll see later how to preserve data using volumes.
What does an imageDocker contain?
An image contains everything an application needs to run. The goal is to ensure that the application launches the same way, no matter where it is executed.
Let’s take the example of an image intended to host a PHP website. It can include a minimal systemLinux, a web server, and the necessary PHP environment.
Simplified diagram:
Image PHP + Apache
│
├── Linux minimal
├── Apache
├── PHP
└── Extensions PHP
With this approach, the same environment can be used on a personal computer, a server, or in the cloud, with exactly the same result. This is one of the great strengths ofDocker Docker: the reproducibility of environments.
Images are built in layers
An imageDockeris not a single file. It is composed of several layers. Each layer generally corresponds to a build step, such as installing software, adding files, or a specific configuration.
Here is a simplified example:
Layer 1 : Linux
Layer 2 : Installation Apache
Layer 3 : Installation PHP
Layer 4 : Configuration
This organization offers a significant advantage:Docker can reuse existing layers. If multiple images use the same baseLinux or the same PHP installation, these layers will be shared.
This reduces disk space usage and speeds up downloads and image builds.
Key Takeaway
An imageDockercan be viewed as the base template for an application. It is immutable, composed of several layers, and is used solely to create containers.
The concept can be summarized as follows:
- Image = template
- Container = running instance
DockerNow that we know what an image is, a new question naturally arises: where are these images stored, and how do we retrieve them?
DockerIn the next lesson, we’ll explore the true “supermarket” of images.