You will see what a built image consists of and what the tag after the colon means.
Each Dockerfile instruction leaves a layer in the image — a snapshot of what it changed in the files. docker history shows the layers, the newest on top; the format keeps two columns, the size and the instruction:
The bottom line is the base from FROM: the busybox image, 4.58 MB. Its layer is shared by every image based on busybox and is stored on disk once. The site layers of its own weigh kilobytes, and CMD has 0B: this instruction changes no files, it records an image setting.
A tag is the version name after the colon: site:1, site:2. Without a tag docker uses latest. A tag points to a specific image, and one image can have several tags. A build with a tag that is already taken moves it to the new image. The old one is left without a name: sudo docker ps shows a container from it with the image ID instead of the name.
The machine has no network, and docker pull does not work. The preparation loaded the FROM base from a file: docker load -i /opt/images/busybox.tar. alpine.tar and nginx-alpine.tar sit next to it.
The web container runs from the site:2 image. You edited index.html and ran sudo docker build -t site:2 . again. What does web serve now?
-
A tag in use does not stop the build: it ends with
naming to docker.io/library/site:2 done, and the old image is left without a tag. -
Losing the tag does not stop the container:
sudo docker psshows web asUp, with the old image's ID in the IMAGE column. -
docker needs the tag when it creates a container. The running web was created from the old image and serves its files until it is re-created.
A container stays on the image it was created from, even after the tag moves to a new one — docker ps shows the old image's ID for it. The new version reaches the site once web is re-created from the new site:2.
Key points
-
Each Dockerfile instruction is an image layer;
docker historylists them from the newest down to the base. -
The base layer from
FROMis shared by every image built on that base. - A tag is an image's version name: a build with a taken tag moves it to the new image, while a running container stays on its own.