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 小时前
培训PDF保护配置:把需求转换成可验收权限
linux·服务器·网络
Felven4 小时前
中科驭数100G网卡RDMA性能测试
linux·rdma·中科驭数·100g网卡
普通人66 小时前
WebGL与WebGPU入门指南
开发语言·webgl·1024程序员节
xbzb6 小时前
自建镜像仓库:registry 一条命令 + harbor 部署、授权、跨库同步与卸载
docker·harbor·镜像·仓库·同步·registry
雪落漂泊6 小时前
Liunux进程(七):程序控制篇(中)
linux·运维·windows
俊俊几年的6 小时前
动态规划(Dynamic Programming)详解:从入门到 LeetCode Hot 100
linux·c++·算法·leetcode·嵌入式·动态规划·c
星恒随风15 小时前
MySQL 从零入门(五):MySQL 内置函数详解——日期、字符串、数学函数与实战案例
linux·数据库·笔记·sql·mysql
唐墨12320 小时前
linux kernel 比较数据大小的宏定义
linux·算法
程序开发阿元20 小时前
密码不进工具:一个独立开发者的服务器凭据管理办法
linux·ssh
猫猫不是喵喵.1 天前
从0到1创建一个微服务项目
java·数据库·微服务·1024程序员节