From point A to point B
Point A: you download images with docker pull and you have already pushed one to Docker Hub, but you do not know exactly where nginx comes from or how to store images that must not be public. Point B: by the end of this chapter you will read the full name of any image, work with public and private registries, and run your own registry to push and pull images on your network.
What a registry is
A registry is a server that stores images and serves them to whoever asks. Inside, each image lives in a repository, and each repository keeps several versions identified by tags.
When you run docker run nginx without having the image, Docker downloads it from the default registry: Docker Hub. Besides hosting public and private images, Docker Hub offers reviewed official images, search and vulnerability scanning.
You build and push from one machine; any other machine with access pulls the same image. Diagram: The House of Routing.
Anatomy of an image name
What you type as nginx is a shorthand. The full name has up to four parts:
If you leave out the registry, Docker uses docker.io; if you leave out the user, library; if you leave out the tag, latest. Diagram: The House of Routing.
| What you type | What Docker understands |
|---|---|
nginx | docker.io/library/nginx:latest |
YOUR_USER/thor-api:1.1 | docker.io/YOUR_USER/thor-api:1.1 |
ghcr.io/org/app:2.0 | GitHub Container Registry |
localhost:5000/thor-api:1.1 | A registry on your own machine, port 5000 |
library is the namespace for Docker Hub's official images, such as nginx, redis or postgres. All the others are prefixed with the user or organization that publishes them.
Public and private registries in the cloud
Docker Hub is not the only one. Every cloud provider has its own private registry, integrated with its permissions and its container services:
| Registry | Address format |
|---|---|
| Docker Hub | docker.io/user/image |
| GitHub Container Registry | ghcr.io/user/image |
| Amazon ECR | ACCOUNT.dkr.ecr.REGION.amazonaws.com/image |
| Google Artifact Registry | REGION-docker.pkg.dev/PROJECT/REPO/image |
| Azure Container Registry | NAME.azurecr.io/image |
There are also public registries for specific projects. Kubernetes, for example, publishes its components on registry.k8s.io.
Logging in to a registry
To push images, or to pull private ones, you first authenticate:
docker login # Docker Hub
docker login ghcr.io # another registry: give its address
docker logout ghcr.io
Use an access token instead of your password: you can limit its permissions (read-only, for example) and revoke it without changing your password. Docker stores the credentials in the system's secure store if one is configured; if not, they stay in ~/.docker/config.json.
Your own registry with the registry image
Docker publishes the registry as just another image, registry, based on the open source project CNCF Distribution. With one command you have a private registry on your machine or on a server:
docker run -d -p 5000:5000 --restart always --name registry \
-v registry-data:/var/lib/registry \
registry:3
--restart alwaysstarts it again if it stops or if you reboot the host.- The volume keeps the pushed images even if you recreate the container.
To push an image, give it a name that starts with the registry's address:
docker tag thor-api:1.1 localhost:5000/thor-api:1.1
docker push localhost:5000/thor-api:1.1
# From another machine on your network
docker pull 192.168.1.50:5000/thor-api:1.1
The registry has an HTTP API. You can query its contents:
curl http://localhost:5000/v2/_catalog
# {"repositories":["thor-api"]}
curl http://localhost:5000/v2/thor-api/tags/list
# {"name":"thor-api","tags":["1.1"]}
localhost without encryption, but from another machine it requires HTTPS. For a real registry, give it a TLS certificate and authentication. Adding the address to insecure-registries in the daemon configuration is fine for a lab, never for production.Lab: push, delete and recover
Check that the image lives in the registry and not only on your machine:
# 1. Registry running
docker run -d -p 5000:5000 --restart always --name registry \
-v registry-data:/var/lib/registry registry:3
# 2. Push an image
docker pull nginx:stable
docker tag nginx:stable localhost:5000/my-nginx:1.0
docker push localhost:5000/my-nginx:1.0
curl http://localhost:5000/v2/_catalog
# 3. Delete it from your machine
docker image rm nginx:stable localhost:5000/my-nginx:1.0
docker images | grep nginx # nothing
# 4. Recover it from the registry
docker pull localhost:5000/my-nginx:1.0
docker run -d -p 8080:80 localhost:5000/my-nginx:1.0
# Clean-up: unused images, the registry and its volume
docker image prune -a
docker rm -f registry && docker volume rm registry-data
Careful: docker image prune -a deletes every image not used by a container, not just the lab ones.
Challenge
Answer before you open the solution. Getting it wrong here is the cheapest way to learn.
1. What is the full name of the redis image?
docker.io/library/redis:latest. The Docker Hub registry, the official images namespace and the default tag.
2. You run docker push thor-api:1.1. Where does Docker try to push it?
To docker.io/library/thor-api, where you have no permissions. Tag it first with your username or your registry's address.
3. What do you need to push an image to a registry at localhost:5000?
Its name has to start with localhost:5000/. The registry address is part of the image name.
4. Why use an access token instead of your password in docker login?
Because you can limit its permissions and revoke it without touching your password or any other access.
5. You recreate the registry container. Do you lose the pushed images?
No, if you mounted a volume on /var/lib/registry. Without a volume, they are lost with the container.
What you take away
- A registry stores image repositories; Docker Hub is the default registry.
- Full name:
registry/user/repository:tag. - Every cloud has its private registry: ECR, Artifact Registry, ACR; and GitHub has GHCR.
- Authenticate with access tokens and never share them.
registry:3gives you your own registry; tag with its address andpush.- Beyond
localhost, a registry needs TLS and authentication.
In the next chapter: how Docker works on Mac and Windows, when containers are Linux.
Official resources
- What is a registry?docs.docker.com
- Docker Hubdocs.docker.com
- docker logindocs.docker.com
- registry (official image)hub.docker.com
- CNCF Distributiondistribution.github.io
- Access tokensdocs.docker.com
Source and credits. Chapter written from Jesús Espinoza's study notes on KodeKloud's Docker for Absolute Beginners course (December 2024). Text drafted with AI assistance; original diagrams by The House of Routing. Technical details were checked against the official Docker documentation.