docker 设置镜像仓库代理

  1. 创建 Docker 服务的代理配置文件
bash 复制代码
sudo mkdir -p /etc/systemd/system/docker.service.d

2.创建文件 /etc/systemd/system/docker.service.d/http-proxy.conf,内容如下:

bash 复制代码
[Service]
Environment="HTTP_PROXY=http://192.168.0.111:7890"
Environment="HTTPS_PROXY=http://192.168.0.111:7890"
Environment="NO_PROXY=localhost,127.0.0.1"
  1. 重新加载并重启 Docker
bash 复制代码
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl restart docker

4.验证配置是否生效

执行:

bash 复制代码
docker info | grep -i proxy

应输出:

bash 复制代码
HTTP Proxy: http://192.168.0.111:7890
HTTPS Proxy: http://192.168.0.111:7890
No Proxy: localhost,127.0.0.1
  1. 再次尝试拉取镜像或执行 Docker 命令
bash 复制代码
docker pull hello-world