>_ IzzyLab

Hands-on task

This task is step 7 of the course “Docker from scratch”

Images: tags and removal

easy~7 min

Several versions of the shop/app application image have piled up on the server: 1.0, 1.1 and 2.0. The app container runs from 2.0.

  1. Remove the images of versions 1.0 and 1.1 — they're no longer needed.
  2. Give the shop/app:2.0 image one more name — shop/app:stable.

The 2.0 image and the app container must stay.

What you'll practise:
  • docker images
  • docker rmi
  • docker tag

Topic breakdown

An image's full name is repository:tag, for example nginx:1.27-alpine. A tag is just a label, usually a version. If no tag is given, Docker uses latest; that's not "the newest version", just a tag with that name.

Images are downloaded with docker pull and the tag you need, for example docker pull nginx:1.27-alpine (docker run does it itself if the image is missing). The lab has no internet access, so there's nothing to download here — you work with what's already there.

One image can carry several names: docker tag adds a name, and docker rmi removes it (Untagged). The image itself is deleted (Deleted) when its last name is removed. Docker won't let you delete an image a container was created from while that container exists.

docker tag busybox:1.36 tools/bb:test   # a second name for the same image
docker rmi tools/bb:test                # remove it

What's checked

  1. The old versions 1.0 and 1.1 are removed
  2. Image 2.0 has one more name, shop/app:stable, and shop/app:2.0 and the app container are still there

What it looks like