โShow me how to tag my image as username/myapp:v1.0.0 and push it to Docker Hub, plus when to also push a :latest tag. Explain semantic versioning briefly.โ
10 โ Push image to Docker Hub
Category: Registry ยท Priority: High
Tag correctly:
docker tag myapp yourusername/myapp:v1.0.0. Learn semantic versioning. Also try thelatesttag.
๐ฏ What is this task?
A Docker image is built on your computer, but to share it or deploy it to the cloud, you need to push it to a registry โ a storage service for Docker images. Docker Hub is the most popular free option (like GitHub, but for Docker images).
๐ค AI Prompt
"Explain step by step how to tag a local Docker image and push it to Docker Hub. The local image is called
my-docker-app. My Docker Hub username isyourusername. Show the exact commands for: logging in, tagging with a version and latest, pushing, and then pulling it back to verify."
๐ Step-by-step
Step 1 โ Create a Docker Hub account
Go to https://hub.docker.com and sign up for a free account. Remember your username.
Step 2 โ Log in to Docker Hub from terminal
docker login
Enter your Docker Hub username and password when prompted. You should see Login Succeeded.
Step 3 โ Tag your image
Docker images need to be tagged with your username before pushing. Replace yourusername with your actual Docker Hub username:
docker tag my-docker-app:v5 yourusername/my-docker-app:v1.0.0
docker tag my-docker-app:v5 yourusername/my-docker-app:latest
You now have two tags for the same image โ a specific version and latest.
Step 4 โ Push to Docker Hub
docker push yourusername/my-docker-app:v1.0.0
docker push yourusername/my-docker-app:latest
You'll see progress bars as each layer uploads. After it completes, go to https://hub.docker.com/r/yourusername/my-docker-app in your browser โ your image should appear there.
Step 5 โ Verify by pulling it back
Delete your local copy and pull it from Docker Hub to confirm it works:
docker rmi yourusername/my-docker-app:latest
docker pull yourusername/my-docker-app:latest
docker run -p 3000:3000 yourusername/my-docker-app:latest
Open http://localhost:3000 โ it should work, now running from the cloud-pulled image.
๐ก Good habits for image tagging
- Use semantic versioning:
v1.0.0,v1.1.0,v2.0.0 - Always also tag as
latestfor convenience - Never push images with secrets or credentials baked in
โ Done when
- Docker Hub account created
-
docker loginsucceeds - Image pushed to
yourusername/my-docker-app:v1.0.0andlatest - Image visible on hub.docker.com
-
docker pull yourusername/my-docker-app:latestworks from terminal
๐ Quiz
Answer all 2 questions correctly to complete this lesson.