Docker 国内镜像源配置

第 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/
相关推荐
疯华整猫3 小时前
一条 kill -9 杀不掉的进程:AI 时代,程序员为什么必须精通 Linux
linux
爆米花byh5 小时前
在RockyLinux9环境下安装Rust1.100.0环境
linux·rust
爆米花byh5 小时前
在RockyLinux9环境下安装Manticore Search32.1.3单机版
linux·服务器·搜索引擎
大今野5 小时前
技能六 · Linux(CentOS 7)操作系统章节习题
linux·运维·centos·专转本
我命由我123456 小时前
Android Gradle - Android Gradle 配置
android·java·linux·java-ee·kotlin·android studio·android-studio
机智阳6 小时前
系统优化(高级)
linux·运维·编辑器
.道阻且长.6 小时前
Linux基础IO:缓冲区 和 库函数的实现
linux·运维·服务器
皓月盈江7 小时前
Windows 复制文件夹到 Linux 后显示“带锁”解决方法
linux·运维·windows·linux文件·文件带锁·文件夹带锁
byte轻骑兵7 小时前
异构混合环境远程控制工具适配对比(Windows / Mac / Linux / 国产系统 / arm64 / 鸿蒙)
linux·windows·macos·远程办公
Meaauf8 小时前
Registry私有容器镜像仓库搭建
docker·容器·registry