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"

相关推荐
XH-hui1 分钟前
【打靶日记】VulNyx 之 Responder
linux·网络安全·vulnyx
赖small强4 分钟前
【Linux驱动开发】 Linux `/proc` 虚拟文件系统深度解析与实战指南
linux·驱动开发·/proc·/proc/sys`·/proc/net
HalvmånEver10 分钟前
Linux:进程创建(进程控制一)
linux·运维·服务器·学习·进程·fork
陈聪.11 分钟前
MySQL全平台安装指南:Windows与Linux详细教程
linux·windows·mysql
泻水置平地17 分钟前
Docker下安装ES和kibana详细教程
elasticsearch·docker·容器
卡次卡次125 分钟前
注意点:多线程与多进程与在并行读-->并行cpu或者GPU处理--->并行写 的架构中,如何选择
linux·网络·python
vortex528 分钟前
基于 Apache 规则拦截目录扫描器请求:实测与配置指南
linux·网络安全·apache
摸鱼仙人~31 分钟前
Ubuntu系统安装VMware Tools 完整流程(解压→安装)
linux·运维·ubuntu
我不是8神32 分钟前
Docker知识点总结
运维·docker·容器
CodeByV33 分钟前
【Linux】线程同步与互斥深度解析:从锁机制到生产者消费者模型
linux