Publish: 2023-12-14 | Modify: 2023-12-14
Due to certain reasons, the official Docker Hub repository is no longer accessible in China. If you are in a Chinese network environment, you can configure a domestic mirror to solve the problem of failed or slow Docker image pulling.
If the /etc/docker/daemon.json
configuration file does not exist, you can use the following command directly:
# 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 and add them to the configuration:
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
]
Don't forget to restart the Docker service:
# Restart Docker service
sudo systemctl daemon-reload
sudo systemctl restart docker
Note: It is recommended to set at least 2 mirror addresses, as some mirrors may not be updated in a timely manner, resulting in the inability to pull the latest tags. However, setting too many mirror addresses may affect performance!
Enter the docker info
command, and you can see the list of "Registry Mirrors," indicating that the configuration was successful. As shown in the following image:
At this point, you can test by pulling an image, such as:
# Pull the Debian image
docker pull debian
By setting up a domestic mirror for Docker Hub, you can solve the problem of failed or slow Docker image pulling. It is recommended to set 2-4 mirror addresses. Over time, some mirror addresses may become invalid. If you encounter any problems, please leave a comment for feedback!
This article references: Docker Hub 镜像加速器
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.