How to Tag and Push Docker Image to Registry
Use
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] to add a new tag to your image, then use docker push TARGET_IMAGE[:TAG] to upload it to a registry. The TARGET_IMAGE usually includes the registry URL and repository name.Syntax
The tagging and pushing process uses two main commands:
- docker tag: Assigns a new name or tag to an existing image.
- docker push: Uploads the tagged image to a remote registry.
Format:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] docker push TARGET_IMAGE[:TAG]
SOURCE_IMAGE is your local image name or ID. TARGET_IMAGE includes the registry URL, repository, and tag.
bash
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
docker push TARGET_IMAGE[:TAG]Example
This example shows how to tag a local image named myapp:latest to a remote registry docker.io/username/myapp:v1.0 and push it.
bash
docker tag myapp:latest docker.io/username/myapp:v1.0 docker push docker.io/username/myapp:v1.0
Output
The push refers to repository [docker.io/username/myapp]
123456789abc: Pushed
v1.0: digest: sha256:abcdef1234567890 size: 1234
Common Pitfalls
Common mistakes include:
- Forgetting to tag the image with the full registry path before pushing.
- Not logging in to the registry with
docker loginbefore pushing. - Using incorrect tag names or missing tags, which defaults to
latest.
Always verify the image tag matches the registry path.
bash
docker push myapp:latest # Error: repository does not exist or no access # Correct way: docker tag myapp:latest docker.io/username/myapp:v1.0 docker push docker.io/username/myapp:v1.0
Quick Reference
| Command | Purpose |
|---|---|
| docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] | Add a new tag to an existing image |
| docker push TARGET_IMAGE[:TAG] | Upload the tagged image to a remote registry |
| docker login | Authenticate to a registry before pushing |
| docker images | List local images and tags |
Key Takeaways
Always tag your image with the full registry path before pushing.
Use docker push to upload the tagged image to the remote registry.
Login to the registry using docker login to avoid permission errors.
Tags help identify image versions; avoid pushing untagged images.
Verify image names and tags with docker images before pushing.