Skip
Arish's avatar

7. Tagging Images


Image Naming Convention

[registry/]repository[:tag] docker.io/library/nginx:1.24 └─────┬─────┘└───┬───┘└─┬─┘└┬┘ registry namespace repo tag

Tagging Images

bash
1# Tag an existing image
2docker tag nginx:latest myregistry/nginx:v1.0
3
4# Tag for Docker Hub
5docker tag myapp:latest username/myapp:latest
6
7# Multiple tags
8docker tag myapp:latest myapp:v1.0
9docker tag myapp:latest myapp:stable

Tagging Best Practices

bash
1# Version tags
2myapp:1.0.0
3myapp:1.0
4myapp:1
5
6# Environment tags
7myapp:production
8myapp:staging
9
10# Git-based tags
11myapp:abc123f
12myapp:main-abc123f

Example Workflow

bash
1# Build with tag
2docker build -t myapp:1.0.0 .
3
4# Also tag as latest
5docker tag myapp:1.0.0 myapp:latest
6
7# Push both
8docker push myapp:1.0.0
9docker push myapp:latest