0
0
Dockerdevops~5 mins

Docker Hub public and private repos - Commands & Configuration

Choose your learning style9 modes available
Introduction
Docker Hub is a place where you can store and share your container images. Public repos are free and visible to everyone, while private repos keep your images secret and only accessible to you or your team.
When you want to share your app image with the world for others to use or learn from.
When you need to keep your app image private for security or business reasons.
When you want to organize your images in a central place accessible from any computer.
When you want to automate deployment by pulling images directly from Docker Hub.
When you want to control who can see or download your images.
Commands
This command logs you into Docker Hub so you can push or pull images from your account.
Terminal
docker login
Expected OutputExpected
Login with your Docker ID to push and pull images from Docker Hub Username: exampleuser Password: Login Succeeded
Tags your local image 'my-app' with your Docker Hub username and repo name so it can be pushed.
Terminal
docker tag my-app exampleuser/my-app:latest
Expected OutputExpected
No output (command runs silently)
Uploads your tagged image to your Docker Hub repository, making it available online.
Terminal
docker push exampleuser/my-app:latest
Expected OutputExpected
The push refers to repository [docker.io/exampleuser/my-app] latest: digest: sha256:abcdef1234567890 size: 1234
Downloads the image from Docker Hub to any machine, so you can run it there.
Terminal
docker pull exampleuser/my-app:latest
Expected OutputExpected
latest: Pulling from exampleuser/my-app Digest: sha256:abcdef1234567890 Status: Downloaded newer image for exampleuser/my-app:latest
Logs you out of Docker Hub to keep your credentials safe when you finish working.
Terminal
docker logout
Expected OutputExpected
Removing login credentials for https://index.docker.io/v1/
Key Concept

If you remember nothing else, remember: public repos share images openly, private repos keep images secure and restricted.

Common Mistakes
Trying to push an image without logging in first
Docker Hub requires authentication to push images, so the push will fail.
Always run 'docker login' and enter your credentials before pushing images.
Not tagging the image with your Docker Hub username before pushing
Docker won't know which repository to push to, causing an error.
Use 'docker tag' to add your username and repo name to the image before pushing.
Trying to pull a private image without logging in
Private images require authentication, so pulling without login will be denied.
Run 'docker login' with your credentials before pulling private images.
Summary
Log in to Docker Hub to authenticate your actions.
Tag your local images with your Docker Hub username and repo name before pushing.
Push images to Docker Hub to share or store them.
Pull images from Docker Hub to use them on any machine.
Log out when done to protect your credentials.