Skip to content

Docker_registry

Docker Registry is a storage and distribution system for Docker images. This chapter covers using public and private registries.

┌─────────────────────────────────────────────────────────────────────────────┐
│ Docker Registry Concept │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Registry │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ nginx │ │ node │ │ python │ │ myapp │ │ │
│ │ │ latest │ │ 18-alpine│ │ 3.11 │ │ v1.0.0 │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
│ Image Format: registry/namespace/repository:tag │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
  • Default public registry
  • Free for public images
  • Paid for private images
  • Enterprise on-premise solution
  • Part of Docker Enterprise
  • Amazon ECR
  • Google Container Registry (GCR)
  • Azure Container Registry (ACR)
  • GitHub Container Registry (GHCR)
  • Harbor
  • GitLab Container Registry
  • Nexus Repository
Terminal window
# Search for images
docker search nginx
# Pull image
docker pull nginx
# Push to Docker Hub
docker tag myapp:latest username/myapp:latest
docker push username/myapp:latest
  • Public repositories (free)
  • Automated builds
  • Webhooks
  • Organization teams
Terminal window
# Login to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 123456789.dkr.ecr.us-east-1.amazonaws.com
# Pull image
docker pull 123456789.dkr.ecr.us-east-1.amazonaws.com/myapp:latest
# Push image
docker tag myapp:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/myapp:latest
docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/myapp:latest
docker-compose.yml
services:
app:
image: 123456789.dkr.ecr.us-east-1.amazonaws.com/myapp:latest
Terminal window
# Start registry
docker run -d -p 5000:5000 --name registry registry:2
# Tag image for local registry
docker tag myapp:latest localhost:5000/myapp:latest
# Push to local registry
docker push localhost:5000/myapp:latest
# Pull from local registry
docker pull localhost:5000/myapp:latest
Terminal window
# Create certificates
mkdir -p certs
openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key -x509 -days 365 -out certs/domain.crt
# Start registry with TLS
docker run -d \
--name registry \
-p 5000:5000 \
-v $(pwd)/certs:/certs \
-e REGISTRY_HTTP_ADDR=0.0.0.0:5000 \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
registry:2
Terminal window
# Download Harbor installer
wget https://github.com/goharbor/harbor/releases/download/v2.9.0/harbor-offline-installer-v2.9.0.tgz
# Extract
tar xvf harbor-offline-installer-v2.9.0.tgz
# Configure
cp harbor.yml.tmpl harbor.yml
# Edit harbor.yml with your settings
# Install
./install.sh
Terminal window
# Login
docker login harbor.example.com
# Tag image
docker tag myapp:latest harbor.example.com/myproject/myapp:latest
# Push
docker push harbor.example.com/myproject/myapp:latest
Terminal window
# List all images in registry (using registry API)
curl -s https://registry.example.com/v2/_catalog | jq
# List image tags
curl -s https://registry.example.com/v2/myapp/tags/list | jq
Terminal window
# Delete manifest (referenced by digest)
curl -X DELETE https://registry.example.com/v2/myapp/manifests/sha256:abc123...
# Run garbage collection
docker exec registry /bin/registry garbage-collect /etc/registry/config.yml
Terminal window
# Login to Docker Hub
docker login
# Login to private registry
docker login registry.example.com
# Login with username
docker login -u username registry.example.com
{
"auths": {
"registry.example.com": {
"auth": "base64-encoded-credentials"
}
}
}
┌─────────────────────────────────────────────────────────────────────────────┐
│ Image Promotion Pipeline │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Build → Dev Registry → Staging Registry → Production Registry │
│ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────────┐ │
│ │ Build │───▶│ Dev │───▶│ Staging │───▶│ Production │ │
│ │ Server │ │ Registry │ │Registry │ │ Registry │ │
│ └─────────┘ └─────────┘ └─────────┘ └─────────────┘ │
│ │
│ myapp:dev myapp:staging myapp:prod │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

In this chapter, you learned:

  • Docker registry concepts
  • Using Docker Hub
  • Amazon ECR setup and usage
  • Running private registries
  • Harbor registry
  • Registry authentication and operations