Image Registries
Push, pull, and manage images with Docker Hub and GitHub Container Registry
Skills taught: docker.registry, docker.push, docker.pull, docker.tagging, docker.ghcr
What is a registry?
A container registry is to Docker what npm is to Node.js — a central place to publish, store, and distribute images. When you run docker pull nginx, Docker downloads from Docker Hub by default. You push your own images to a registry so they can be pulled by CI/CD pipelines, teammates, and servers worldwide.
Docker Hub — the default public registry
# 1. Create a free account at hub.docker.com
# 2. Log in from the CLI
docker login
# Username: prashantkeshr
# Password: ********
# 3. Tag your image with your Docker Hub username
# Format: docker tag <local-image>:<tag> <username>/<repo>:<tag>
docker tag myapp:1.0 prashantkeshr/myapp:1.0
docker tag myapp:1.0 prashantkeshr/myapp:latest
# 4. Push
docker push prashantkeshr/myapp:1.0
docker push prashantkeshr/myapp:latest
# 5. Anyone can now pull it
docker pull prashantkeshr/myapp:latest
GitHub Container Registry (GHCR) — preferred for open source
# GHCR is free with GitHub, supports private images, and integrates
# natively with GitHub Actions. Use it for any project on GitHub.
# 1. Create a Personal Access Token (PAT) with 'write:packages' scope
# Settings → Developer settings → Personal access tokens → Classic
# 2. Log in to GHCR
export CR_PAT=<your-token>
echo $CR_PAT | docker login ghcr.io -u prashantkeshr --password-stdin
# 3. Tag for GHCR — format: ghcr.io/<github-username>/<repo>:<tag>
docker tag myapp:1.0 ghcr.io/prashantkeshr/myapp:1.0
docker tag myapp:1.0 ghcr.io/prashantkeshr/myapp:latest
# 4. Push
docker push ghcr.io/prashantkeshr/myapp:latest
# 5. Pull (public packages can be pulled without auth)
docker pull ghcr.io/prashantkeshr/myapp:latest
Tagging strategy
# In a real CI pipeline you'd tag with multiple identifiers:
GIT_SHA=$(git rev-parse --short HEAD) # e.g. a3f2c1d
VERSION=$(cat VERSION) # e.g. 1.4.2
# Build once, tag multiple ways
docker build -t myapp:latest .
docker tag myapp:latest myapp:$VERSION # 1.4.2
docker tag myapp:latest myapp:$GIT_SHA # a3f2c1d (for rollback)
docker tag myapp:latest myapp:stable # stable alias
# Push all tags
docker push myapp:latest
docker push myapp:$VERSION
docker push myapp:$GIT_SHA
# Why SHA tags? If a deployment goes wrong, you can pinpoint exactly
# which commit was running and roll back to the previous SHA tag instantly
Tip: Never use :latest in production. :latest is a moving target — it means 'whatever was last pushed' and makes deployments non-reproducible. In production, always pin to a specific version tag or git SHA so you know exactly what's running and can roll back deterministically.
Frequently Asked Questions
What other registries exist besides Docker Hub and GHCR?
AWS Elastic Container Registry (ECR), Google Artifact Registry (GAR), Azure Container Registry (ACR), and GitLab Container Registry. Cloud registries are preferred in enterprise because they integrate with cloud IAM (no separate credentials), have better availability SLAs, and often include vulnerability scanning. GHCR is the best choice for GitHub-hosted open source projects.