Sub topic 3
Why Docker Image Pushes Get Faster
Assume Docker is installed and running, you can build images, and you have a Docker Hub account. A Docker image consists of read-only layers, such as a base system and application files. Docker uploads only layers that the registry does not already have.
A digest is a content-based identifier for an image or layer. If the content has not changed, its digest stays the same. Therefore, a second push can reuse existing layers.
Public and private repositories
A public repository lets anyone pull your image. Use it for open-source software or examples. A private repository restricts pulls to authorized users or teams. Choose visibility before sharing the image, and avoid putting secrets in any image layer because visibility settings cannot make embedded secrets safe.
Access tokens and common errors
Use a Docker Hub personal access token instead of your account password. Store it in an environment variable or a CI secret:
echo "$DOCKERHUB_TOKEN" | docker login -u YOUR_USERNAME --password-stdin
docker push YOUR_USERNAME/myapp:1.0A denied or requested access to the resource is denied error usually means one of these:
- You logged in as a different user.
- The image name uses the wrong namespace.
- The repository does not exist, or your account cannot write to it.
- The tag was not created with
docker tag.
Check the name with docker image ls, then tag it as YOUR_USERNAME/repository:version.
Multi-platform images
Different CPU architectures need compatible image variants. Build and push both common variants with Buildx:
docker buildx build --platform linux/amd64,linux/arm64 \
-t YOUR_USERNAME/myapp:1.0 --push .Docker Hub stores a manifest that selects the correct variant when a user pulls the tag.
CI automation
A continuous integration (CI) workflow can publish after changes reach main. Keep DOCKERHUB_USERNAME and DOCKERHUB_TOKEN in repository secrets:
name: publish
on:
push:
branches: [main]
jobs:
push-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/myapp:latestExercise
Why might a second push upload fewer bytes than the first?
Show answer
Docker Hub already has unchanged layers identified by their digests, so Docker uploads only new or changed layers.