How to Configure Docker Hub Domestic Mirrors to Fix Pull Failures

docker hub mirrordocker pull faileddocker registry mirrorsdocker daemon.jsondocker mirror configuration
Published·Modified·

Due to certain reasons, the official Docker Hub repository cannot be pulled from within China. If you are in a domestic network environment, you can configure domestic mirrors to solve Docker image pull failures or slow speeds.

Configure Docker Mirror Source

If the /etc/docker/daemon.json configuration file does not exist, you can directly use the following command:

# Create directory
sudo mkdir -p /etc/docker
# Write mirror configuration
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": [
        "https://docker.m.daocloud.io",
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn"
    ]
}
EOF
# Restart Docker service
sudo systemctl daemon-reload
sudo systemctl restart docker

If the /etc/docker/daemon.json configuration file already exists, manually copy the following mirror addresses into the configuration:

"registry-mirrors": [
        "https://docker.m.daocloud.io",
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn"
    ]

Do not forget to restart the Docker service:

# Restart Docker service
sudo systemctl daemon-reload
sudo systemctl restart docker

Note: It is recommended to set more than 2 mirror addresses, as some mirrors may not be updated in time, leading to the inability to pull the latest tags. However, do not set too many, as this may affect performance!

Verification

Enter the docker info command to see the "Registry Mirrors" address list, indicating that the setup was successful, as shown in the figure below:

b077e81132367679.png

At this point, you can pull any image to test, for example:

# Pull Debian image
docker pull debian

Conclusion

By configuring domestic Docker Hub mirrors, you can solve Docker image pull failures and slow speeds. It is recommended to set 2-4 mirror addresses. As time passes, some mirror addresses may become invalid. If you encounter any issues, please leave a message for feedback!

This article references: Docker Hub Mirror Accelerator