CentOS Docker仓库和代理配置

无法直接访问外部网络时,除了Host自己的全局代理设置之外,需要单独给Docker Client和Instance设置代理。

如执行docker run时遇到下面的错误

bash 复制代码
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp 3.216.34.172:443: i/o timeout.
See 'docker run --help'.

可以通过修改Docker仓库和代理配置

修改Docker仓库

/etc/docker/daemon.json

bash 复制代码
# vi /etc/docker/daemon.json
# cat daemon.json
{
  "registry-mirrors": [
        "https://docker.mirrors.ustc.edu.cn",
        "https://hub-mirror.c.163.com",
        "https://mirror.baidubce.com"
  ]
}

修改Docker Client代理配置

/etc/systemd/system/docker.service.d/proxy.conf

bash 复制代码
# vi /etc/systemd/system/docker.service.d/proxy.conf
# cat proxy.conf
[Service]
Environment="HTTP_PROXY=http://IP:Port/"
Environment="HTTPS_PROXY=http://IP:Port/"
Environment="NO_PROXY=https://registry-1.docker.io/v2/"

修改Docker Instance代理配置

~/.docker/config.json

bash 复制代码
[xxx]# cat ~/.docker/config.json
{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://IP:Port/",
     "httpsProxy": "http://IP:Port/",
     "noProxy": "127.0.0.0/8"
   }
 }
}

或者在启动Docker时添加环境变量参数

--env HTTP_PROXY="http://IP:Port"

--env HTTPS_PROXY="https://IP:Port"

--env FTP_PROXY="ftp://IP:Port"

--env NO_PROXY="127.0.0.0/8"

相关推荐
程序设计实验室7 分钟前
经历分享,发现挖矿木马后,服务器快速备份与重装(腾讯云平台)
linux
Miku162 小时前
OpenClaw-Linux+飞书官方Plugin安装指南
linux·人工智能·agent
Miku162 小时前
OpenClaw 接入 QQ Bot 完整实践指南
linux·人工智能·agent
Yogurt_cry7 小时前
[树莓派4B] 闲置近10年的爱普生 L310 打印机爆改无线打印机
linux·物联网·树莓派
Johny_Zhao1 天前
OpenClaw中级到高级教程
linux·人工智能·信息安全·kubernetes·云计算·yum源·系统运维·openclaw
Sheffield2 天前
Docker的跨主机服务与其对应的优缺点
linux·网络协议·docker
Sheffield2 天前
Alpine是什么,为什么是Docker首选?
linux·docker·容器
马艳泽2 天前
win10下运行Start Broker and Proxy报错解决
docker
Johny_Zhao3 天前
centos7安装部署openclaw
linux·人工智能·信息安全·云计算·yum源·系统运维·openclaw