Tagging and pushing images
docker tag, login and push: what each does to your image, what goes over the wire, where credentials end up, and a tagging scheme that survives production.
Image names: repositories, tags and digestsDocker Hub and other registries
Tagging and pushing images
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- docker tag adds another name to an image you already have. Nothing is copied, and the name decides which registry and repository a push goes to.
- docker login stores credentials for one registry host, in a credential helper if one is configured, or base64-encoded in ~/.docker/config.json if not.
- docker push uploads only the blobs the registry doesn't already have, then puts the manifest under the tag. Shared base layers say 'Layer already exists'.
- A push prints the digest. That digest, not the tag, is what to record and deploy.
- Tag each build with something unique and permanent, such as the Git commit SHA, add human tags like 1.4.2, and never push a different image under an existing version tag.
From your laptop to everyone’s server
You’ve built notes-api and it runs locally. Now the CI runner, staging and three production hosts need it. They can’t reach your laptop, so the image goes to a registry, and every host pulls it from there. Three commands do it: tag names the image for its destination, login proves you may write there, and push uploads it. Each is simple. The decisions around them, which names and which credentials, are what bite later.
docker tag: a new name, not a copy
docker build -t notes-api:dev .
docker tag notes-api:dev ghcr.io/acme/notes-api:1.4.2
docker tag notes-api:dev ghcr.io/acme/notes-api:sha-3f9c2e1
docker images ghcr.io/acme/notes-api
The tag reference describes the target as [HOST[:PORT]/]NAMESPACE/REPOSITORY[:TAG]. Tagging adds a name to an existing image. No layers are copied, so all three names show the same image ID. The name matters because it is the address. docker push sends ghcr.io/acme/notes-api:1.4.2 to ghcr.io, repository acme/notes-api, under tag 1.4.2. With no host it goes to Docker Hub, as image names explained. You can skip the separate step by giving docker build several -t flags.
docker login: credentials per host
echo "$GHCR_TOKEN" | docker login ghcr.io -u acme-bot --password-stdin
docker login # Docker Hub
Credentials are stored per registry host. Where they go depends on ~/.docker/config.json. With a credential helper (credsStore: "desktop" on Docker Desktop, osxkeychain, pass or secretservice on Linux), the secret sits in the OS keychain. Without one, it’s written into config.json as base64, which is an encoding, not encryption. On shared build machines, use a helper or log out at the end of the job. Always use --password-stdin rather than -p, so the token doesn’t land in shell history and process lists. Use access tokens, not account passwords: a Docker Hub access token, a GitHub token with write:packages, or a cloud provider’s short-lived token.
docker push: only what’s missing
A push follows the OCI distribution spec. For each layer and the config, the client asks the registry whether it already has that digest (HEAD /v2/<name>/blobs/<digest>). If not, it tries a cross-repository mount, POST /v2/<name>/blobs/uploads/?mount=<digest>&from=<other repo>, so the registry links a blob it holds elsewhere. Failing that, it uploads. Last, it PUTs the manifest under the tag, and the registry replies with the digest.
That’s why pushes of a new version are small. An image built on python:3.14-slim reuses its four base layers, which I measured at 43,546,016 bytes compressed. If the registry already has them, only your app’s layers travel, and the output says Layer already exists for the rest. The last line, of the form 1.4.2: digest: sha256:<64 hex characters> size: <manifest bytes>, is the one to keep. Record that digest in your deploy, not the tag. docker push -a pushes every tag of a repository. With the containerd image store, --platform pushes one platform’s manifest as a single-platform image.
A tagging scheme that survives production
Tags are mutable. The registry lets you overwrite 1.4.2 tomorrow. Discipline has to come from you and the registry settings:
- A unique, permanent tag per build: the Git commit, such as
sha-3f9c2e1. Every image traces back to its source. - Human release tags:
1.4.2, plus moving convenience tags1.4and1if consumers want them. Push a version tag once and never again. - Environment pointers, if any, as moving tags:
staging,prod. Deploy by digest anyway. - Turn on tag immutability where the registry offers it (ECR, Artifact Registry, Harbor and others), so a second push of
1.4.2fails. - Label the image with
org.opencontainers.image.sourceandorg.opencontainers.image.revision. GHCR uses the source label to link the package to its repository.
In CI the build, tag and push is usually one step, docker buildx build --push -t … -t …, with the CI lesson covering the rest and build once, promote through environments explaining why the same digest should move from staging to production.
About the video
The embed is the “Container registries” chapter of DevOps Directive’s “Complete Docker Course - From BEGINNER to PRO!”, April 2023, from 2:23:46 to 2:33:45, 10 minutes. Per the course’s companion written lesson, it covers what a registry is, authenticating, tagging for and pushing to Docker Hub and to GitHub Container Registry, and tagging practice: avoid latest, give one image several useful tags, treat tags as immutable, and use timestamps, build IDs, commit hashes and semver. It doesn’t show what a push sends over the wire or how credentials are stored, which the lesson adds. English was judged from the channel and its English caption track. Brian Morrison’s video in deeper does the GHCR push by hand and from GitHub Actions.
What was run: the base-layer sizes come from the python:3.14-slim amd64 manifest fetched from Docker Hub’s registry API. Nothing was tagged, logged in or pushed, since there is no Docker here. The push sequence and the mount endpoint are from the OCI distribution spec 1.1.1, and the CLI behaviour from the docker image tag, push and login references, checked 2026-11-28.
Where this fits
Public registries aren’t the only option. Next, hosting your own: running a private registry.
Check yourself
You run docker tag notes-api:dev registry.example.com/team/notes-api:1.4.2. How much extra disk does that use?
Almost none. A tag is just another name pointing at the same image. No layers are copied.
docker push ghcr.io/acme/notes-api:1.4.2 fails with 'unauthorized' although docker login worked this morning. What should you check?
That you logged in to ghcr.io specifically, since credentials are per host, and that the token has the write:packages scope and access to that organization's package.
Why does pushing a new version of an image built on python:3.14-slim often upload only a few megabytes?
The registry already has the shared base layers, so the client checks each blob, skips the existing ones, and may mount them from another repository. Only the new application layers travel.
Why is pushing a fresh build over an existing version tag like 1.4.2 a bad idea?
Anything that already pulled 1.4.2 has different bytes from anything that pulls it later, so rollbacks, caches and audits stop meaning what they say. Use a new tag and let registries enforce immutability.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.