第 1 步:编辑 Docker 配置文件
打开终端,使用文本编辑器(如 nano 或 vim)打开或创建 Docker 的守护进程配置文件:
bash
sudo nano /etc/docker/daemon.json
或者
bash
sudo vim /etc/docker/daemon.json
第 2 步:替换为可用的镜像源
docker 镜像配置:
json
{
"registry-mirrors": [
"https://docker.1ms.run",
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
]
}
第 3 步:重启 Docker 服务
保存文件并退出编辑器(在 nano 中按 Ctrl+O 保存,Enter 确认,Ctrl+X 退出),然后重新加载配置并重启 Docker:
bash
sudo systemctl daemon-reload
sudo systemctl restart docker
第 4 步:验证并重新拉取
验证镜像源是否已成功加载:
bash
docker info | grep -A 5 "Registry Mirrors"
如果输出中显示了新的镜像源地址,如:
bash
root@ubuntu-26:~# docker info | grep -A 5 "Registry Mirrors"
Registry Mirrors:
https://docker.1ms.run/
https://docker.mirrors.ustc.edu.cn/
https://hub-mirror.c.163.com/
https://mirror.baidubce.com/
Live Restore Enabled: false
即可重新运行测试:
bash
docker run hello-world
出现以下内容代表成功:
bash
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d5e71e642bf5: Download complete
4f55086f7dd0: Pull complete
Digest: sha256:11a3eb1597e864c51b3f56733cb2e8a90bf0c284bfc05f9444d81c558bc848aa
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/