Skip to content

Local Container Registry Setup

A local Docker registry allows you to store and distribute container images within your development environment without relying on external services like Docker Hub.

  • Docker installed and running
  • Basic understanding of Docker images and tags
  1. Run Local Registry

    Start a registry container on port 5000:

    Terminal window
    docker run -d -p 5000:5000 --name registry registry:2
  2. Verify Registry is Running

    Terminal window
    docker ps | grep registry
  3. Tag an Image

    Tag an existing image for your local registry:

    Terminal window
    docker tag my-app:latest localhost:5000/my-app:latest
  4. Push to Local Registry

    Terminal window
    docker push localhost:5000/my-app:latest
  5. Pull from Local Registry

    Terminal window
    docker pull localhost:5000/my-app:latest

By default, the registry stores images in the container. To persist data, use a volume:

Terminal window
docker run -d \
-p 5000:5000 \
--name registry \
-v /path/to/registry:/var/lib/registry \
registry:2

Create a password file:

Terminal window
mkdir auth
docker run --entrypoint htpasswd httpd:2 -Bbn myuser mypassword > auth/htpasswd

Run registry with authentication:

Terminal window
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:2

Login to the registry:

Terminal window
docker login localhost:5000

For production-like environments, configure TLS:

Terminal window
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:2
docker-compose.yml
version: '3'
services:
registry:
image: registry:2
ports:
- "5000:5000"
volumes:
- ./registry-data:/var/lib/registry
restart: always

Start the registry:

Terminal window
docker-compose up -d

View all images stored in your local registry:

Terminal window
curl http://localhost:5000/v2/_catalog

View tags for a specific image:

Terminal window
curl http://localhost:5000/v2/my-app/tags/list
Terminal window
docker stop registry
docker rm registry
Terminal window
rm -rf /path/to/registry

Ensure the registry container is running:

Terminal window
docker ps | grep registry

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.