加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

docker – 无法找到图像错误,如何设置代理以下载图像

发布时间:2020-12-16 03:28:36 所属栏目:安全 来源:网络整理
导读:我需要设置公司代理,以便Docker可以从公共注册表下载图像. $sudo docker run hello-world Unable to find image 'hello-world:latest' locally Pulling repository docker.io/library/hello-world Error while pulling image: Get https://index.docker.io/v

我需要设置公司代理,以便Docker可以从公共注册表下载图像.

$sudo docker run hello-world 
Unable to find image 'hello-world:latest' locally 
Pulling repository docker.io/library/hello-world 
Error while pulling image: Get https://index.docker.io/v1/repositories/library/hello-world/images: dial tcp: lookup index.docker.io: no such host

我正在使用Ubuntu 12.04机器.我找到了this answer但是在Ubuntu 12.04中没有systemctl.我怎样才能做到这一点?

谢谢.

最佳答案
来自Docker官方文档,

为docker服务创建systemd插件目录:

$sudo mkdir -p /etc/systemd/system/docker.service.d

创建一个名为/etc/systemd/system/docker.service.d/http-proxy.conf的文件,该文件添加了HTTP_PROXY环境变量:

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"

或者,如果您位于HTTPS代理服务器后面,请创建名为/etc/systemd/system/docker.service.d/https-proxy.conf的文件,该文件添加HTTPS_PROXY环境变量:

[Service]
Environment="HTTPS_PROXY=https://proxy.example.com:443/"

如果您有内部Docker注册表,您需要联系而无需代理,您可以通过NO_PROXY环境变量指定它们:

[Service]    
Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"

或者,如果您在HTTPS代理服务器后面:

[Service]    
Environment="HTTPS_PROXY=https://proxy.example.com:443/" "NO_PROXY=localhost,docker-registry.somecorporation.com"

同花顺变化:

$sudo systemctl daemon-reload

重启Docker:

$sudo systemctl restart docker

验证是否已加载配置:

$systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/

或者,如果您在HTTPS代理服务器后面:

$systemctl show --property=Environment docker
Environment=HTTPS_PROXY=https://proxy.example.com:443/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读