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"

相关推荐
M78佐菲6 小时前
ARM学习笔记(1)
linux·arm开发·笔记·嵌入式硬件·学习
益达丫7 小时前
Socket编程揭秘:端口、IP与进程通信的底层逻辑
linux·笔记
九皇叔叔9 小时前
Kubernetes 资源管理方式详解:命令式与声明式管理
docker·容器·k8s
chicheese10 小时前
Linux 面试速查表:从初级到高级,附高频场景答题模板
linux·运维
Linux-lucky10 小时前
32-38-Linux学习之旅之MySQL综合
linux·运维·学习·mysql·ubuntu
vortex511 小时前
常用终端模拟器全面对比:Kitty、WezTerm、Ghostty 与 Konsole
linux
INGNIGHT12 小时前
270 · 电话号码的字母组合II(Trie)
linux·算法
zly350012 小时前
VMware Converter Standalone 物理机转化为虚拟机后源1硬盘变成了2个硬盘(2个硬盘文件)虚拟机无法启动。
linux·运维·服务器
GeW14 小时前
从内核到数据:Linux与工业数据库如何支撑高端制造
linux
程序猿小郑15 小时前
Docker Compose 构建完整服务实战指南:从入门到最佳实践
docker·容器