Sub topic 3
Why and when to use a private registry
This chapter assumes you can build an image with a Dockerfile, run a container, and use the command line. It also assumes you know that an image reference has a host, a repository, and a tag. Later chapters cover logging in and the specific registries.
What "private" means
A private registry requires credentials to pull images, to push images, or both. The registry software is the same as a public one. The difference is access control. Anonymous users get a "denied" or "not found" response instead of your image.
Privacy applies at the repository level. One registry can hold public and private repositories side by side. GHCR, for example, lets you set visibility per package.
Reasons to keep images private
- Proprietary code. An image contains your compiled application and often your source files. Anyone who can pull it can unpack the layers and read them.
- Secrets baked in by mistake. Images sometimes contain
.envfiles, API keys, or private package registry tokens. A deleted file still exists in an earlier layer. Private access limits the damage, but it does not make this safe. Keep secrets out of images. - Compliance. Some regulations and customer contracts require you to control who can access software artifacts and to keep an audit trail.
- Supply chain control. If only your CI system can push to a repository, then what runs in production came from your pipeline. A public repository that many people can push to gives you no such guarantee.
- Rate limits and availability. Public registries such as Docker Hub limit anonymous and free pulls. A registry inside your own cloud account avoids those limits and keeps deployments working if the public service has an outage.
- Network and cost. Pulling from a registry in the same cloud region as your cluster is fast. Traffic between services in one region is often cheaper than traffic out to the internet.
When a public registry is fine
Not every image needs to be private. Open-source projects publish public images so that anyone can run them. Base images like python or nginx come from public repositories. A reasonable setup is to pull public base images, build your application on top of them, and push the result to a private repository.
A decision checklist
Ask these questions about each image:
- Does it contain code or data you do not want others to see?
- Do you need to limit who can push or deploy it?
- Will many nodes pull it often enough to hit rate limits?
- Does your organization require audit logs or access reviews?
If you answer yes to any of them, use a private repository.
How a private pull works
The client asks the registry for an image. The registry replies that it needs credentials. The client authenticates, receives a token, and repeats the request with it.
Every tool that pulls images follows this flow. That includes your laptop, your CI runners, and the Kubernetes nodes. Each one needs its own credentials. Most private-registry problems come from one of these places missing or having the wrong credentials.
Costs to plan for
A private registry adds work. You must manage credentials, rotate them, and give each system access. Storage also grows with every pushed image, so you need a cleanup policy. Hosted registries charge for storage and sometimes for data transfer. These costs are usually small compared with the risk of leaking proprietary images.
Exercise
Your team builds a web service from the public node base image and adds proprietary code. Which repositories should be private, and why?
Show answer
The repository holding your built service image should be private, because its layers contain your proprietary code. The node base image can stay public. You pull it from the public registry and push only your own image to a private repository.