Pushing & Pulling Images
Log in, tag an image for a registry, then use docker push to upload and docker pull to download it.
Syntax
docker push username/repository:tagSharing an image means pushing it to a registry; using someone's image means pulling it.
The push workflow
- Log in with
docker login. - Tag the image with your registry username or host.
- Push it with
docker push.
The naming rule
To push to Docker Hub, the image must be tagged as username/repository:tag. The username tells the registry where it belongs.
Example
# 1. Authenticate
docker login
# 2. Tag your local image for your Docker Hub account
docker tag myapp:1.0 myuser/myapp:1.0
# 3. Push it to the registry
docker push myuser/myapp:1.0
# On another machine, pull it back
docker pull myuser/myapp:1.0When to use it
- A developer tags and pushes a new application image to Docker Hub so team members can pull the latest version without access to the source code.
- A CI pipeline builds an image, tags it with the git commit SHA, and pushes it to a private registry as a deployment artifact.
- An ops engineer pulls a pinned image by digest rather than tag to guarantee an immutable, bit-for-bit identical deployment.
More examples
Tag and push to Docker Hub
Builds an image, adds a Docker Hub namespace tag, and pushes it to the repository.
docker build -t myapp:1.2.0 .
docker tag myapp:1.2.0 myusername/myapp:1.2.0
docker push myusername/myapp:1.2.0Pull a specific image by digest
Pulling by digest guarantees the exact image bytes regardless of whether the tag was overwritten.
# Pull by immutable digest (not mutable tag)
docker pull myusername/myapp@sha256:abc123def456...
# Find digest of a local image
docker inspect myapp:1.2.0 --format '{{.RepoDigests}}'Push to GitHub Container Registry
Authenticates to GHCR and pushes an image using the ghcr.io prefix to target GitHub's registry.
echo $GITHUB_PAT | docker login ghcr.io -u myusername --password-stdin
docker tag myapp:1.2.0 ghcr.io/myorg/myapp:1.2.0
docker push ghcr.io/myorg/myapp:1.2.0
Discussion