11. Container Registries
A Docker Registry is a highly scalable, centralized server application that stores and distributes Docker images. Without a registry, there would be no easy way to move an image you built on your laptop to a production server in the cloud.
11.1 Registry Fundamentals
Section titled “11.1 Registry Fundamentals”Understanding the hierarchy of how images are stored is essential for navigating registries.
Registry
Section titled “Registry”The top-level storage server or service itself (e.g., Docker Hub, Amazon ECR, GitHub Container Registry). A registry contains multiple repositories.
Repository
Section titled “Repository”A collection of related images inside the registry, usually representing a single application (e.g., my-company/frontend-app).
The actual read-only file system layers and execution configuration stored inside the repository.
The human-readable label pointing to a specific version of the image inside the repository (e.g., v1.2.0, latest).
Digest
Section titled “Digest”The immutable, cryptographic SHA256 hash that uniquely identifies the exact contents of the image.
11.2 Docker Hub
Section titled “11.2 Docker Hub”Docker Hub (hub.docker.com) is the default, massive public registry maintained by Docker. It hosts millions of community images and certified “Official” images (like Alpine, Nginx, Postgres).
Authentication
Section titled “Authentication”Before you can push images (or pull from private repos), you must log in using the Docker CLI.
docker login# It will prompt for your username and password/access tokenTo download an image from Docker Hub to your local machine:
docker pull ubuntu:22.04To upload an image you built to Docker Hub, you must tag it with your exact Docker Hub username first.
# Tag the local imagedocker tag my-app:latest myusername/my-app:1.0
# Push it to Docker Hubdocker push myusername/my-app:1.0Private Repositories
Section titled “Private Repositories”By default, pushing to Docker Hub makes the image completely public. If your image contains proprietary source code, you must explicitly create a Private Repository in the Docker Hub web UI, ensuring only authenticated team members can pull the image.
11.3 Private Registry Architecture
Section titled “11.3 Private Registry Architecture”Enterprise teams rarely use Docker Hub for their internal applications. Instead, they use private registries (like AWS Elastic Container Registry, Google Artifact Registry, or a self-hosted Harbor instance).
The CI/CD Flow
Section titled “The CI/CD Flow”Understanding how a private registry sits at the center of the deployment pipeline:
Developer (Writes Code & Dockerfile) ↓ CI Pipeline (Runs `docker build`) ↓ Private Registry (Stores the resulting Image securely) ↓ Production Server (Runs `docker pull` to fetch and run the Image)- The developer pushes code to GitHub.
- An automated CI/CD server (like GitHub Actions) authenticates with the Private Registry, builds the Docker image, and runs
docker push. - The production server is notified, authenticates with the Private Registry, runs
docker pull, and deploys the new container. (The production server never sees the source code; it only receives the pre-compiled image).
11.4 Registry Security
Section titled “11.4 Registry Security”Registries are massive targets for hackers. If a registry is compromised, attackers can inject malicious code into the base images used across your entire infrastructure.
Authentication & Authorization
Section titled “Authentication & Authorization”Registries must strictly control who can access them.
- Authentication (AuthN): Proving who you are (using Access Tokens instead of passwords).
- Authorization (AuthZ): Proving what you are allowed to do. A production server should only be granted
pull(read) access, while a CI/CD server is grantedpush(write) access.
TLS (Transport Layer Security)
Section titled “TLS (Transport Layer Security)”All communication between the Docker daemon and the Registry must occur over HTTPS/TLS. This prevents Man-in-the-Middle (MitM) attacks from intercepting the image layers as they travel over the internet.
Image Signing (Docker Content Trust)
Section titled “Image Signing (Docker Content Trust)”How do you guarantee the image wasn’t tampered with? Image signing allows the developer (or CI server) to cryptographically sign the image before pushing it. Before the production server runs the image, Docker verifies the digital signature. If the signature is invalid or missing, the server refuses to run the container.
Vulnerability Scanning
Section titled “Vulnerability Scanning”Modern private registries automatically scan images the moment they are pushed. They analyze the image layers against CVE (Common Vulnerabilities and Exposures) databases and alert you if your image contains outdated libraries with known security flaws (like Heartbleed or Log4j).