Local Container Registry Setup
Overview
Section titled “Overview”A local Docker registry allows you to store and distribute container images within your development environment without relying on external services like Docker Hub.
Prerequisites
Section titled “Prerequisites”- Docker installed and running
- Basic understanding of Docker images and tags
Quick Setup
Section titled “Quick Setup”-
Run Local Registry
Start a registry container on port 5000:
Terminal window docker run -d -p 5000:5000 --name registry registry:2 -
Verify Registry is Running
Terminal window docker ps | grep registry -
Tag an Image
Tag an existing image for your local registry:
Terminal window docker tag my-app:latest localhost:5000/my-app:latest -
Push to Local Registry
Terminal window docker push localhost:5000/my-app:latest -
Pull from Local Registry
Terminal window docker pull localhost:5000/my-app:latest
Persistent Storage
Section titled “Persistent Storage”By default, the registry stores images in the container. To persist data, use a volume:
docker run -d \ -p 5000:5000 \ --name registry \ -v /path/to/registry:/var/lib/registry \ registry:2Configuration Options
Section titled “Configuration Options”With Authentication
Section titled “With Authentication”Create a password file:
mkdir authdocker run --entrypoint htpasswd httpd:2 -Bbn myuser mypassword > auth/htpasswdRun registry with authentication:
docker run -d \ -p 5000:5000 \ --name registry \ -v "$(pwd)"/auth:/auth \ -e "REGISTRY_AUTH=htpasswd" \ -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" \ registry:2Login to the registry:
docker login localhost:5000With TLS/SSL
Section titled “With TLS/SSL”For production-like environments, configure TLS:
docker run -d \ -p 5000:5000 \ --name registry \ -v "$(pwd)"/certs:/certs \ -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \ -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \ registry:2Using with Docker Compose
Section titled “Using with Docker Compose”version: '3'services: registry: image: registry:2 ports: - "5000:5000" volumes: - ./registry-data:/var/lib/registry restart: alwaysStart the registry:
docker-compose up -dList Images in Registry
Section titled “List Images in Registry”View all images stored in your local registry:
curl http://localhost:5000/v2/_catalogView tags for a specific image:
curl http://localhost:5000/v2/my-app/tags/listCleanup
Section titled “Cleanup”Stop and Remove Registry
Section titled “Stop and Remove Registry”docker stop registrydocker rm registryRemove Registry Data
Section titled “Remove Registry Data”rm -rf /path/to/registryTroubleshooting
Section titled “Troubleshooting”Connection Refused
Section titled “Connection Refused”Ensure the registry container is running:
docker ps | grep registryPush/Pull Fails
Section titled “Push/Pull Fails”If using a non-localhost address, you may need to configure Docker to allow insecure registries. Edit /etc/docker/daemon.json:
{ "insecure-registries": ["myregistry.local:5000"]}Restart Docker after making changes.