Tagging images
- Docker & Kubernetes course
- Beginner
- Lesson 26/82
- 4 min
Learn to tag images with the -t flag.
Tagging images
A full image name has the form [registry/][user/]repository:tag. The tag usually shows the version. One build can get several tags:
docker build -t api:1.4.2 -t api:1.4 -t api:latest .
docker build -t ghcr.io/ali/api:1.4.2 .Semantic versioning (major.minor.patch) is common: 1.4.2 is fixed, while 1.4 and latest are moving tags pointing at the latest patch.
A tag is a pointer
A tag is a name pointing at an image ID (content digest); the same image can have several tags. docker tag adds a new name, the image isn't copied:
$ docker tag api:1.4.2 ali/api:1.4.2
$ docker images
REPOSITORY TAG IMAGE ID SIZE
api 1.4.2 4f1e2d3c4b5a 162MB
ali/api 1.4.2 4f1e2d3c4b5a 162MB # same IDPractice Multiple tags
Write the command that produces the tags api:2.0.1, api:2.0 and api:latest from the current folder with a single build.
Starter code
# buraya yazExpected output
[+] Building 0.4s (10/10) FINISHED => naming to docker.io/library/api:2.0.1 done => naming to docker.io/library/api:2.0 done => naming to docker.io/library/api:latest done
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Why is a fixed version tag used in production instead of latest?
- latest can't be pulled
- latest is only for Windows
- latest may point at different images over time; rollback and reproduction get hard Correct answer
- latest is slower
Explanation: Knowing which version runs is the first step of debugging.
2 Give an existing image a new name.
docker ____ api:1.4.2 ali/api:1.4.2
docker tag api:1.4.2 ali/api:1.4.2
Explanation: docker tag source target.
3 Match.
| Term | Meaning |
|---|---|
1.4.2 |
Fixed version |
1.4 |
Moving minor version |
ghcr.io/ |
Registry address |
IMAGE ID |
Content ID |