You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Docker daemon优先使用本地Registry,Docker Hub作为降级源?

Absolutely feasible! This is a super common setup for teams wanting to speed up image pulls, cut down on external bandwidth usage, and have a reliable fallback when their local registry goes down. Let’s walk through exactly how to set this up:

Step 1: Configure the Docker Daemon

First, you’ll need to edit (or create) the Docker daemon configuration file—usually located at /etc/docker/daemon.json on Linux systems. Here’s what the config should look like:

{
  "registry-mirrors": ["http://your-local-registry:5000"],
  "insecure-registries": ["your-local-registry:5000"]
}
  • registry-mirrors: This tells Docker to first attempt to pull images from your local registry before falling back to Docker Hub. The order here is critical—we put the local registry first so it’s prioritized for all pull requests.
  • insecure-registries: Only add this line if your local registry uses HTTP (instead of HTTPS). Docker blocks unencrypted registry connections by default, so this whitelists your local instance to bypass that restriction.

After saving the file, restart the Docker daemon to apply the changes:

sudo systemctl restart docker
Step 2: Verify the Configuration

You can confirm the daemon picked up your settings correctly with this quick check:

docker info | grep -A5 "Registry Mirrors"

You should see your local registry listed under the "Registry Mirrors" section of the output.

Step 3: Test the Fallback Behavior

Let’s validate the exact scenario you described:

  1. Ensure myimage:0.1 exists in both your local registry and Docker Hub.
  2. Run docker pull myimage:0.1—Docker will first reach out to your local registry and pull the image from there.
  3. Temporarily take down your local registry (e.g., stop its container with docker stop registry).
  4. Run docker pull myimage:0.1 again. Docker will detect the local registry is unavailable, automatically fall back to Docker Hub, and pull the image from the public repository.
Bonus: Pull-Through Caching (Optional)

If you want your local registry to automatically cache images from Docker Hub when they’re not already stored locally, you can set it up as a pull-through cache. After the first pull of an external image, subsequent pulls will use the local cached copy. To enable this, start your registry with the --mirror flag:

docker run -d -p 5000:5000 --restart always --name registry registry:2 --mirror https://registry-1.docker.io

This turns your local registry into a proxy that mirrors Docker Hub, combining the priority of local images with automatic caching of external ones for future use.

内容的提问来源于stack exchange,提问作者jdomingo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:21:24