Docker
Container Registry
Private Registry
DevOps
Configuration

How to change the default docker registry from docker.io to my private registry?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Many teams want Docker commands to use a private registry instead of Docker Hub for speed, security, and policy control. The important detail is that Docker does not fully replace unqualified image name resolution in a single switch. In practice, you combine registry mirrors, explicit image naming, and daemon policy to get behavior that feels like a private default.

Understand What Can and Cannot Be Changed

When you run docker pull nginx, Docker resolves that image as docker.io/library/nginx unless a mirror is configured. A mirror can intercept pulls for Docker Hub content, but it does not change every image reference rule in the client.

So there are two goals:

  • Route Docker Hub traffic through your private infrastructure.
  • Make your own images come from your private registry by naming convention.

Treat these as separate controls. This avoids confusion during rollout and makes troubleshooting easier.

Option 1: Use a Pull Through Mirror for Docker Hub

A registry mirror is the fastest way to reduce direct dependency on Docker Hub. Start a private registry in proxy mode.

yaml
1# config.yml for registry:2
2version: 0.1
3proxy:
4  remoteurl: https://registry-1.docker.io
5storage:
6  filesystem:
7    rootdirectory: /var/lib/registry
8http:
9  addr: :5000

Run it with Docker.

bash
1docker run -d \
2  --name registry-mirror \
3  -p 5000:5000 \
4  -v /opt/registry/config.yml:/etc/docker/registry/config.yml \
5  -v /opt/registry/data:/var/lib/registry \
6  registry:2

Then point the Docker daemon to the mirror.

json
{
  "registry-mirrors": ["http://registry.internal.example:5000"]
}

On Linux this goes in /etc/docker/daemon.json, followed by:

bash
sudo systemctl restart docker

Now pulls for Docker Hub content are served through the mirror cache when possible.

Option 2: Use Explicit Private Image Names for Your Artifacts

For your own services, always tag with full registry host. Example:

bash
docker build -t registry.internal.example/team/api:1.4.2 .
docker push registry.internal.example/team/api:1.4.2

Pull with the same full name in deployment manifests.

bash
docker pull registry.internal.example/team/api:1.4.2

This is the only deterministic way to ensure your application images come from private infrastructure. Relying on short names introduces ambiguity and accidental pulls from public sources.

Option 3: Add Security and Trust Configuration

If your registry uses a private certificate authority, install the CA certificate on every Docker host. For test environments without TLS you can mark the registry as insecure, but keep that limited to non production.

json
1{
2  "registry-mirrors": ["http://registry.internal.example:5000"],
3  "insecure-registries": ["registry.internal.example:5000"]
4}

Then authenticate once per host or use credential helpers.

bash
docker login registry.internal.example

For production, prefer HTTPS with a trusted certificate and remove insecure entries.

Verify the Setup End to End

Validation should check both mirror behavior and private push pull flow.

bash
1# Check daemon settings
2docker info | grep -A 5 "Registry Mirrors"
3
4# Pull a public image and confirm mirror access in registry logs
5docker pull alpine:3.20
6
7# Push and pull private artifact
8docker build -t registry.internal.example/team/demo:0.1 .
9docker push registry.internal.example/team/demo:0.1
10docker pull registry.internal.example/team/demo:0.1

If pull latency drops after the first request and mirror logs show cached blobs, the mirror is working as expected.

Rollout Strategy for Teams

A safe migration plan looks like this:

  1. Enable mirror on a staging Docker host.
  2. Update CI pipelines to use fully qualified private image names.
  3. Add a lint rule that rejects unqualified images in deployment files.
  4. Roll daemon config to production hosts with controlled batches.
  5. Track pull failures and auth errors during the first week.

This phased approach reduces incident risk and gives clear rollback points.

Common Pitfalls

  • Expecting Docker to globally remap every short image name to a private host. Mirror behavior is narrower than that.
  • Using insecure registry mode in production. This can expose credentials and image traffic.
  • Forgetting to update CI tags. Builds may still push to Docker Hub if image names are not fully qualified.
  • Mixing mirror and direct pull paths without documentation. Operators then cannot explain where an image came from.
  • Skipping certificate distribution for private CA. Hosts fail with TLS errors even when registry is healthy.

Summary

  • Docker cannot be fully switched to a new default namespace with one daemon flag.
  • Use a registry mirror to proxy Docker Hub content through private infrastructure.
  • Tag your own images with full private registry names for deterministic source control.
  • Configure TLS and authentication correctly, and avoid insecure mode outside development.
  • Validate mirror and private artifact flows separately, then roll out gradually across hosts.

Course illustration
Course illustration

All Rights Reserved.