Sub topic 6
Pushing the image
This chapter covers the push step itself: what docker push sends, what its output means, and how to read it. It assumes you have Docker running, a free Docker Hub account, and a local image built from a Dockerfile. It also assumes you already know how image names are structured and have logged in with docker login.
What a push does
docker push uploads a local image to the repository named in its argument. The name must include your namespace, which is your Docker Hub username. An image called myapp:1.0 is addressed to the library or to a registry you don't control. An image called YOUR_USERNAME/myapp:1.0 is addressed to your own repository.
Docker does not upload the image as one file. It splits the image into layers and digests, and it asks the registry which layers it already has. It then uploads only the missing ones.
Running the push
Start with the small image from the Dockerfile used earlier in this tutorial.
FROM alpine:3.20
CMD ["echo", "Hello from Docker Hub"]Build it, tag it with your namespace, and push it. Replace YOUR_USERNAME with your Docker Hub username.
docker build -t myapp:1.0 .
docker tag myapp:1.0 YOUR_USERNAME/myapp:1.0
docker push YOUR_USERNAME/myapp:1.0The docker tag command adds a second name to the same image. It does not copy any data. Pushing the new name is what targets your repository.
Reading the output
A first push prints something like this:
The push refers to repository [docker.io/YOUR_USERNAME/myapp]
d4fc045c9e3a: Pushed
1.0: digest: sha256:3f1c...e9a2 size: 527Each line starting with a short hex ID is one layer. The status after the colon tells you what happened to it.
| Status | Meaning |
|---|---|
| `Preparing` | Docker is computing the layer for upload. |
| `Waiting` | The layer is queued behind others. |
| `Pushing` | The layer is uploading, usually with a progress bar. |
| `Pushed` | The registry did not have the layer, so Docker uploaded it. |
| `Layer already exists` | The registry already had this layer, so nothing was sent. |
The final line shows the tag, the digest, and the manifest size. The digest is a SHA-256 hash of the image manifest. It identifies this exact image content, and it does not change unless the content changes.
Pushing the same image again
Run the same push a second time. Every layer now reports Layer already exists, and the command finishes almost at once. The digest on the last line is the same as before.
Now change the tag and push again:
docker tag myapp:1.0 YOUR_USERNAME/myapp:1.1
docker push YOUR_USERNAME/myapp:1.1Both tags now point to one digest, and no layer data is uploaded. A tag is only a movable label on a manifest.
Pushing every tag
Pushing a name sends one tag. To send all local tags of a repository, use --all-tags:
docker push --all-tags YOUR_USERNAME/myappGive this command a repository name with no tag. It fails if you add one.
Common mistakes at this step
- Pushing the untagged name.
docker push myapp:1.0fails because Docker tries to reach a repository you do not own. Tag the image with your namespace first. - Forgetting that tags move. Pushing
latestor any existing tag replaces what that tag points to on Docker Hub. The older image stays reachable by its digest, but the tag no longer finds it. - Assuming the push is finished when upload bars stop. Wait for the line that shows the digest. That line confirms the registry accepted the manifest.
Exercise
You push YOUR_USERNAME/myapp:1.0, then run the same command again. The second run prints Layer already exists for every layer and finishes in a second. Why, and what would you expect to see for the digest?
Show answer
Docker Hub already stores every layer with the same content hash, so the CLI has nothing to upload. The manifest is also identical, so the final line shows the same digest as the first push.