Using Docker Hub: Register, Login, Pull, Push Images and Set Up a Private Registry
This guide explains how to create a Docker Hub account, log in, search and pull images, build and tag custom images, push them to Docker Hub, and configure a private Docker registry for local image storage and retrieval, covering all essential Docker commands and options.
Docker Hub
The official Docker Hub public repository hosts over 15,000 images that can be downloaded directly for most needs.
Register & Login
You can register a free Docker account at https://cloud.docker.com . Log in interactively with docker login and log out with docker logout .
$ docker login
Username: your_username
Password: ********
Login SucceededPull Images
Search for images using docker search and download them with docker pull . Example:
$ docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx 7636 [OK]Then pull the image:
$ docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
...Build and Push an Image
Create a Dockerfile :
$ touch Dockerfile
FROM nginx
RUN echo '
Hello, Docker!
' > /usr/share/nginx/html/index.htmlBuild the image:
$ docker build -t nginx:v1 .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM nginx
---> 3f8a4339aadd
Step 2/2 : RUN echo '
Hello, Docker!
' > /usr/share/nginx/html/index.html
---> Using cache
Successfully built 4ac2d12f10cd
Successfully tagged nginx:v1Tag the image for your Docker Hub repository (replace your_username ):
$ docker tag nginx:v1 your_username/nginx:v1Push the image:
$ docker push your_username/nginx:v1
The push refers to repository [docker.io/your_username/nginx]
241cbe531d78: Pushed
a103d141fc98: Pushed
...Private Registry
Run the official registry image to start a local private registry on port 5000:
$ docker run -d -p 5000:5000 --restart=always --name registry registry
Unable to find image 'registry:latest' locally
latest: Pulling from library/registry
...Tag an image for the private registry (e.g., 127.0.0.1:5000 ) and push it:
$ docker tag nginx:latest 127.0.0.1:5000/nginx:latest
$ docker push 127.0.0.1:5000/nginx:latest
The push refers to repository [127.0.0.1:5000/nginx]
a103d141fc98: Pushed
73e2bd445514: Pushed
...Verify the uploaded image via the registry API:
$ curl 127.0.0.1:5000/v2/_catalog
{"repositories":["nginx"]}Remove the local image and pull it back from the private registry:
$ docker rmi 127.0.0.1:5000/nginx:latest
Untagged: 127.0.0.1:5000/nginx:latest
$ docker pull 127.0.0.1:5000/nginx:latest
latest: Pulling from nginx
Digest: sha256:926b086e1234b6ae9a11589c4cece66b267890d24d1da388c96dd8795b2ffcfb
Status: Downloaded newer image for 127.0.0.1:5000/nginx:latestReference: Docker — From Beginner to Practice (https://www.gitbook.com/download/pdf/book/yeasy/docker_practice)
Architect's Tech Stack
Java backend, microservices, distributed systems, containerized programming, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.