📖 Scenario: You are working as a DevOps engineer managing Docker images for your team. You need to organize your Docker images using Docker Hub repositories. Some images should be public for open access, while others must be private for security.
🎯 Goal: Learn how to create Docker Hub repositories, tag images correctly, and push images to both public and private repositories.
📋 What You'll Learn
Create a Docker image named myapp with tag v1
Tag the image for a public Docker Hub repository named username/myapp-public
Tag the image for a private Docker Hub repository named username/myapp-private
Push the image to the public repository
Push the image to the private repository
💡 Why This Matters
🌍 Real World
Docker Hub repositories help teams share container images securely and efficiently, separating public images from private ones.
💼 Career
Understanding Docker Hub public and private repos is essential for DevOps roles managing containerized applications and deployment pipelines.
Progress0 / 4 steps
1
Create a Docker image named myapp:v1
Write a Dockerfile that uses the alpine base image and creates a Docker image named myapp with tag v1. Then build the image using the command docker build -t myapp:v1 .
Docker
Hint
Use FROM alpine as the first line in your Dockerfile. Then run docker build -t myapp:v1 . in the terminal.
2
Tag the image for public and private Docker Hub repositories
Use the docker tag command to tag the image myapp:v1 as username/myapp-public:v1 for the public repo and as username/myapp-private:v1 for the private repo. Replace username with your Docker Hub username.
Docker
Hint
Use docker tag myapp:v1 username/myapp-public:v1 and docker tag myapp:v1 username/myapp-private:v1 to create the tags.
3
Push the image to the public Docker Hub repository
Use the docker push command to push the image tagged as username/myapp-public:v1 to Docker Hub. Make sure you are logged in with docker login before pushing.
Docker
Hint
Run docker push username/myapp-public:v1 to upload the public image.
4
Push the image to the private Docker Hub repository
Use the docker push command to push the image tagged as username/myapp-private:v1 to Docker Hub. Confirm that the private repository is set up in your Docker Hub account.
Docker
Hint
Run docker push username/myapp-private:v1 to upload the private image.
Practice
(1/5)
1. What is the main difference between a public and a private Docker Hub repository?
easy
A. Public repos are open to everyone; private repos restrict access to authorized users only.
B. Public repos require payment; private repos are always free.
C. Public repos can only store images; private repos can store containers.
D. Public repos require docker login; private repos do not.
Solution
Step 1: Understand repository access types
Public repositories are accessible by anyone without restrictions, while private repositories limit access to specific users.
Step 2: Identify the key difference
The key difference is about who can access the repository: public is open, private is restricted.
Final Answer:
Public repos are open to everyone; private repos restrict access to authorized users only. -> Option A
Quick Check:
Access control = Public open, Private restricted [OK]
Hint: Public means open access; private means restricted access [OK]
Common Mistakes:
Confusing payment requirements for public/private repos
Thinking private repos store containers instead of images
Believing public repos require login
2. Which command is used to authenticate your Docker client to access private Docker Hub repositories?
easy
A. docker pull
B. docker login
C. docker push
D. docker build
Solution
Step 1: Identify authentication command
The command docker login is used to provide credentials to Docker Hub for private repo access.
Hint: Use docker login to authenticate before accessing private repos [OK]
Common Mistakes:
Using docker pull to authenticate
Confusing push with login
Trying to build to authenticate
3. What will happen if you try to pull an image from a private Docker Hub repository without logging in first?
medium
A. Docker will automatically log you in using your local credentials.
B. The image will download successfully without any error.
C. Docker will prompt for login credentials or show an authentication error.
D. The image will be pulled but with limited functionality.
Solution
Step 1: Understand private repo access control
Private repositories require authentication before allowing image downloads.
Step 2: Predict Docker behavior without login
If you are not logged in, Docker will deny access and prompt for credentials or show an error.
Final Answer:
Docker will prompt for login credentials or show an authentication error. -> Option C
Quick Check:
Unauthenticated pull from private repo = error prompt [OK]
Hint: Without login, pulling private images triggers authentication error [OK]
Common Mistakes:
Assuming image downloads without login
Thinking Docker auto-logs in
Believing partial image pull is possible
4. You ran docker login but still get 'unauthorized' errors when pulling from a private repo. What is the most likely cause?
medium
A. You logged in with the wrong Docker Hub username or password.
B. The image name is misspelled but login was successful.
C. Docker Hub is down and cannot authenticate users.
D. You need to run docker logout before pulling.
Solution
Step 1: Check login credentials
Unauthorized errors after login usually mean the credentials were incorrect or lack permission.
Step 2: Rule out other causes
Misspelling causes 'not found' errors, not unauthorized. Docker Hub downtime is rare and would affect all users. Logout is not required before pulling.
Final Answer:
You logged in with the wrong Docker Hub username or password. -> Option A
Quick Check:
Unauthorized error after login = wrong credentials [OK]
Hint: Unauthorized after login? Check username/password carefully [OK]
Common Mistakes:
Assuming image name typo causes unauthorized error
Thinking logout fixes unauthorized errors
Blaming Docker Hub downtime without checking credentials
5. You want to push a Docker image to a private repository on Docker Hub named myuser/myapp. Which sequence of commands correctly prepares and uploads the image?