Lab 20: Push Docker Image to Docker Hub¶
Objective
By the end of this lab, you will be able to:
- Tag and push a Docker image to Docker Hub
- Verify the image on your Docker Hub profile
Prerequisites
- Docker installed and image built (Lab 19)
- Docker Hub account
Docker Hub Account Creation¶
In your desktop go to following address:
https://hub.docker.com/- Click on
Sign Up - Select Personal Tab
- Enter your email address
- Put your desired Username
- Enter your password
- Click on
Sign Up
Step 1: Login to Docker Hub¶
docker login -u <your_username>
Step 2: Tag Your Docker Image¶
Replace <your_dockerhub_username> with your actual Docker Hub username:
docker tag flask-demo-app <your_dockerhub_username>/flask-demo-app:v1
Example:
docker tag flask-demo-app sidtrainings/flask-demo-app:v1
What are Docker Tags? Docker tags are used to assign a unique identifier to a Docker image, allowing you to manage and organize different versions of your images. Tags are essentially aliases for image IDs and can be used to specify versions, variants, or other distinguishing characteristics of an image.
Tagging an Image To tag an image in Docker, you can use the
docker tagcommand. This command creates a new tag for an existing image, allowing you to reference the image by the new tag. The general syntax for the docker tag command is:docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
Step 3: Push the Image to Docker Hub¶
docker push <your_dockerhub_username>/flask-demo-app:v1
Step 4: Verify on Docker Hub¶
- Go to https://hub.docker.com
- Login to your account
- Navigate to Repositories and confirm your image
flask-demo-app:v1is listed
(OPTIONAL) Step 5: Pull and Run the Image from Docker Hub¶
Now that your image is on Docker Hub, you (or anyone) can use it anywhere Docker is installed.
🔽 To pull the image:
docker pull your-dockerhub-username/flask-demo-app:v1
your-dockerhub-username with your actual Docker Hub username.
▶️ To run the container:
docker run -d -p 8081:5000 your-dockerhub-username/flask-demo-app:v1
🚀 What’s Next?¶
In Lab 21, you will write a Jenkins pipeline to automate image build and deployment.