Tag and Version Your Images
docker tag gives an image a name and a version. A tag is name:version, and the version part lets you run yesterday's image while today's is tested.
Tag a built image
This command tags the image as version 1.0.
docker tag g4-greet:latest g4-greet:1.0List the tags
Both tags point at the same image.
docker images g4-greet --format "{{.Repository}}:{{.Tag}}"Example
docker build -t g4-greet:1.0 . >/dev/null
docker tag g4-greet:1.0 g4-greet:latest
docker images g4-greet --format "{{.Repository}}:{{.Tag}} {{.Size}}"Key points
- Use docker tag to add a name and version to a built image.
- A tag looks like greet:1.0, with the version after the colon.
- Use 1.0, 1.1, 2.0 for versions, so each release has its own tag.
- Use latest only as a moving pointer, never as the version of record.
- One image can carry many tags at once.
In this example, a build tags the image 1.0, and a second tag calls the same image latest. The listing shows both tags with one size. One image carries two names, and the version tag stays fixed while latest moves.
Note
Retagging does not copy the image. The tags point at the same image ID.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
Why tag an image 1.0 instead of only latest?