Container Registries: Where Docker Images Live
Your pipeline has just built version 1.4.2 of your app as a container image, on a CI runner, a temporary machine wiped when the job ends. Tomorrow three servers must run exactly that image. Where does it wait, and how does each server ask for it? This lesson explains container registries: what they store, how to read an image name, and how pushing, pulling and pinning work.
What a registry stores
As lesson 6 explained, CI builds an artifact once and promotes it unchanged. When that artifact is a container image, the app packed with everything it needs to run, it waits in a container registry: a server that stores images and hands out exact copies.
A registry does not keep an image as one file. An image is a stack of layers, each holding the files one build step added or changed, plus a manifest: a small JSON file that lists the layers and settings by fingerprint. Each distinct layer is stored once, however many images use it (see Docker Image Layers and Caching).
Three names find an image in a registry:
- A repository holds every version of one image, such as
sample-app. - A tag is a readable label on one version, such as
1.4.2. - A digest is the content fingerprint:
sha256:plus 64 hexadecimal characters, a hash of the manifest. Change one byte of any layer and the digest changes too.
Reading an image name
A full image name says which registry to call and what to ask it for: registry/namespace/repository:tag. The namespace is the owner, a user or organisation, so two people's sample-app repositories never clash. The diagram takes apart this course's example, ghcr.io/datsabk/sample-app:1.4.2.
The aha is in the defaults. Leave out the registry and Docker asks Docker Hub, docker.io. Leave out the namespace there and it uses library, reserved for Docker Official Images. Leave out the tag and it assumes latest. So nginx really means docker.io/library/nginx:latest.
To name exact content, write @sha256: and the digest in place of :tag. Repository names must be lowercase, so a GitHub user named DatsABK pushes to ghcr.io/datsabk/.
Push and pull
To push is to upload an image to a registry; to pull is to download one. CI builds and pushes the image once. Each server, or each machine in a cluster (a group of machines managed as one), pulls it and starts a container. In the flowchart, notice the registry in the middle: machines that run your app never need its source code or build tools.
Push and pull move layers, not whole images: Docker skips any layer whose digest the registry already has. When CI runs docker push ghcr.io/datsabk/sample-app:1.4.2 after pushing 1.4.1, its log shows one line per layer, then the digest the registry recorded (trimmed; IDs and digest illustrative):
The push refers to repository [ghcr.io/datsabk/sample-app]
9e1d4c2a7b30: Pushed
5a7c90e1f2d4: Layer already exists
c03b8f6a1e95: Layer already exists
1.4.2: digest: sha256:4b2f… size: 1573
Only the app layer was uploaded, as the diagram below shows. A push that fails with denied or unauthorized means the runner is not logged in, or its token cannot write there.
"Unchanged" means byte for byte. The base layer matches if you build on the same base image version. A dependency layer usually matches only if the build reused it from its cache, which lesson 13 turns on in CI; otherwise it is rebuilt and its new bytes upload again.
A public repository lets anyone pull without logging in; a private one serves only those you allow. Docker Hub (docker.io), the default, is best known for public images. GitHub Container Registry (ghcr.io) keeps images beside your code, each new one private at first. Amazon ECR (Elastic Container Registry) on AWS, and JFrog Artifactory, which stores many kinds of package, are common private choices.
Tags move, digests don't
A tag is a movable label: push another image under an existing tag and the tag now points to it. Most registries allow this; some, such as Amazon ECR, offer tag immutability, a per-repository setting (off by default) that refuses to move a tag. As lesson 6 warned, latest moves most: Docker adds it whenever you give no tag.
A digest cannot move, because it is calculated from the content. Pull by digest and you get those exact bytes or an error, never a lookalike. Several tags can share one digest: if CI also tags 1.4.2 with its commit SHA, 7f3c2a1, both names point to the same image.
So deploy an exact version or a digest, never latest. Kubernetes, which runs containers across many machines, shows why: for latest or no tag, unless you set a pull policy, it asks the registry each time it starts a container, so two machines can run different code under one name. The Kubernetes images guide recommends a version tag and/or a digest instead.
Running a registry: logins, scans and clean-up
Authentication from CI
Pushing always needs a login, as does pulling from a private repository. Machines log in with a token, a generated password that can be limited to certain actions and revoked on its own. Give each the least it needs: CI may write, servers only read.
Prefer short-lived tokens. In GitHub Actions, the GITHUB_TOKEN that GitHub creates for each job expires when the job ends; granted packages: write, it can push to ghcr.io, as lesson 15 shows hands-on. Never commit a long-lived personal token.
Image scanning
Images carry operating system packages and libraries, some with known security flaws, each published with an ID called a CVE (Common Vulnerabilities and Exposures). An image scanner checks the packages in every layer against those lists, like lesson 5's dependency scans. Trivy can run as a pipeline step; Amazon ECR can scan each image on push.
Rescan stored images too: new flaws are found in old packages, though the image's bytes never change.
Retention and clean-up
Every CI run can push an image, and storage costs money or quota. A retention rule deletes images automatically by age or count. Watch for untagged images: when a tag moves on, the old image keeps its digest but loses its label. This Amazon ECR lifecycle policy expires untagged images 14 days after they were pushed:
{
"rules": [
{
"rulePriority": 1,
"description": "Expire untagged images older than 14 days",
"selection": {
"tagStatus": "untagged",
"countType": "sinceImagePushed",
"countUnit": "days",
"countNumber": 14
},
"action": { "type": "expire" }
}
]
}
Never delete what is running or what you may roll back to: running containers keep working, but new servers could not pull the image. The classic mistake is a "keep the last 30" rule on every tag, which also expires old releases still in production; narrow it to release tags with ECR's tagPrefixList.
Check yourself
CI pushes 1.4.3 after a one-line code change. Why does the push take seconds, and what could make it slow again?
Only the app layer is new; the registry has the rest by digest. Skipping the build cache, or a newer base image, makes new layer bytes that upload again.
A teammate re-pushes sample-app:1.4.2 with a hotfix. One new server pulls that tag, another the digest recorded at release. Do they run the same code?
No. The tag now points to the hotfix, so the first gets new code under an old label; the digest names the original content, so the second gets exactly the release.
Should your production servers use the same registry token as CI?
No. Servers only pull, so give them a read-only token: a leaked one cannot push a tampered image for every machine to pull.