Tags
What is tag
Tags are notation for a image, a same image may have multiple tags. But the tag for named image can only represent one image. As long as at least one tag exists for the image, the image itself(distinct by id) won't be removed. So adding a new tag for image actually made a fork from it.
Add tag for existing image
bash
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vue-app latest d70d1656b8d2 32 minutes ago 420MB
ubuntu latest e4c58958181a 5 weeks ago 77.8MB
1
2
3
4
5
6
2
3
4
5
6
bash
docker image tag vue-app vue-app:1
1
The new tag ref to the same container with the same id.
bash
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vue-app 1 d70d1656b8d2 33 minutes ago 420MB
vue-app latest d70d1656b8d2 33 minutes ago 420MB
ubuntu latest e4c58958181a 5 weeks ago 77.8MB
1
2
3
4
5
6
7
2
3
4
5
6
7
Assign tag when build
Assign tag after colon, if not specified, latest
is the default.
bash
docker build --tag vue-app:2 .
1
Remove tag
bash
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vue-app latest 9a138abb00e2 4 minutes ago 420MB
vue-app 1 d70d1656b8d2 3 hours ago 420MB
ubuntu latest e4c58958181a 5 weeks ago 77.8MB
1
2
3
4
5
6
2
3
4
5
6
We perform docker image remove <container:tag>
to remove its fork.
bash
docker image remove vue-app:1
Untagged: vue-app:1
Deleted: sha256:d70d1656b8d292bfaecdee9f943e07580cdbabd8dd9ce7753c94645af2b0f6d9
1
2
3
4
2
3
4
Since it's the last existing image for this image, so when we remove its tag, meaning that this image shall be deleted forever.