CodeBlanks Logo Icon CodeBlanks

docker tag

Learn to give an image a new tag with docker tag.

docker tag

docker tag SOURCE TARGET adds a new name to an existing image. No copy is made; both names point at the same image ID. It is used to repoint moving tags when releasing a version:

docker tag api:1.3.0 api:1.3
docker tag api:1.3.0 api:latest
docker tag api:1.3.0 registry.ornek.com:5000/api:1.3.0

Save and load

To move an image to another machine without a registry, it is saved to a tar archive. save/load carry the image with its layers and tags:

docker save -o api.tar api:1.3.0
scp api.tar sunucu:/tmp/
ssh sunucu docker load -i /tmp/api.tar
# Loaded image: api:1.3.0

Practice Version tags and moving

Write the commands: add the tags api:2.1 and api:latest to the api:2.1.0 image (two commands); then save api:2.1.0 to the file api.tar; finally list the images of the api repository.

Starter code

terminal
# buraya yaz

Sample solution

terminal
docker tag api:2.1.0 api:2.1
docker tag api:2.1.0 api:latest
docker save -o api.tar api:2.1.0
docker images api

Expected output

REPOSITORY   TAG      IMAGE ID       CREATED       SIZE
api          2.1      8c9d0e1f2a3b   2 hours ago   162MB
api          2.1.0    8c9d0e1f2a3b   2 hours ago   162MB
api          latest   8c9d0e1f2a3b   2 hours ago   162MB

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 How does disk usage change after docker tag?

  • It decreases
  • It grows with the number of tags
  • It doesn't change; a new name is added to the same image Correct answer
  • It doubles

Explanation: A tag is only a pointer.

2 Save the image to a tar file.

Question
docker ____ -o api.tar api:1.3.0
Answer
docker save -o api.tar api:1.3.0

Explanation: save outputs the image, export a container's file system.

3 Match.

Term Meaning
docker tag New name
docker save Write the image to tar
docker load Read an image from tar
host:5000/ Private registry

All lessons in Beginner