Sub topic 2
Tagging and Pushing an Image to Docker Hub
Assume Docker is installed and running, you have a Docker Hub account, and a local image already exists. A Docker image name normally has this form:
namespace/repository:tag
Your Docker Hub namespace is usually your username. The repository identifies the project, and the tag identifies a version or release such as 1.0.
Tag the Image for Your Repository
A local image can have a name that Docker Hub cannot accept directly, such as myapp:1.0. Use docker tag to add a second name that includes your namespace:
docker tag myapp:1.0 YOUR_USERNAME/myapp:1.0
docker images YOUR_USERNAME/myappTagging does not copy or rebuild the image. It creates another reference to the same image data. Replace YOUR_USERNAME with your Docker Hub username.
The repository myapp must exist in your Docker Hub account, or Docker Hub must allow it to be created during the first push.
Push the Image
Authenticate before pushing. For interactive use, Docker prompts for the password or token:
docker login -u YOUR_USERNAME
docker push YOUR_USERNAME/myapp:1.0Docker uploads the image's layers to the repository. Layers that already exist remotely do not need to be uploaded again. This makes later pushes faster when only a small part of the image changed.
The tag in the docker push command is important. Pushing YOUR_USERNAME/myapp:latest is different from pushing YOUR_USERNAME/myapp:1.0.
Check the Result
Open the repository page on Docker Hub and confirm that the tag appears. You can also verify the image independently by removing only its local repository tag, pulling it, and running it:
docker rmi YOUR_USERNAME/myapp:1.0
docker pull YOUR_USERNAME/myapp:1.0
docker run --rm YOUR_USERNAME/myapp:1.0The pull output includes a content digest. A digest is a hash that identifies the exact image manifest. Tags can move to different images, but a digest identifies immutable content.
Exercise
Does docker tag rebuild an image before pushing it?
Show answer
No. It adds another name that points to the existing local image.