我在Ubuntu 13.10 (Saucy Salamander)上安装了Docker,当我在控制台输入:
sudo docker pull busybox
我得到以下错误:
Pulling repository busybox
2014/04/16 09:37:07 Get https://index.docker.io/v1/repositories/busybox/images: dial tcp: lookup index.docker.io on 127.0.1.1:53: no answer from server
码头工人版本:
$ sudo docker version
Client version: 0.10.0
Client API version: 1.10
Go version (client): go1.2.1
Git commit (client): dc9c28f
Server version: 0.10.0
Server API version: 1.10
Git commit (server): dc9c28f
Go version (server): go1.2.1
Last stable version: 0.10.0
我在一个没有身份验证的代理服务器后面,这是我的/etc/apt/apt.conf文件:
Acquire::http::proxy "http://192.168.1.1:3128/";
Acquire::https::proxy "https://192.168.1.1:3128/";
Acquire::ftp::proxy "ftp://192.168.1.1:3128/";
Acquire::socks::proxy "socks://192.168.1.1:3128/";
我做错了什么?
按照以下步骤解决问题:
步骤1:sudo systemctl start docker
步骤2:sudo systemctl enable docker
(从/etc/systemd/system/multi-user.target.wants/docker创建符号链接。Service到/usr/lib/systemd/system/docker.service
步骤3:sudo systemctl status docker
步骤4:sudo mkdir -p /etc/systemd/system/docker.service.d
步骤5:sudo vi /etc/systemd/system/docker.service.d/proxy.conf
设置代理如下所示
[Service]
Environment="HTTP_PROXY=http://proxy.server.com:80"
Environment="HTTPS_PROXY=http://proxy.server.com:80"
Environment="NO_PROXY=.proxy.server.com,*.proxy.server.com,localhost,127.0.0.1,::1"
步骤6:sudo systemctl daemon-reload
步骤7:sudo systemctl restart docker.service
步骤8:vi /etc/environment和source /etc/environment
http_proxy=http://proxy.server.com:80
https_proxy=http://proxy.server.com:80
ftp_proxy=http://proxy.server.com:80
no_proxy=127.0.0.1,10.0.0.0/8,3.0.0.0/8,localhost,*.abc.com
下面是代理HTTP的官方Docker文档链接:
https://docs.docker.com/config/daemon/systemd/#httphttps-proxy
简单介绍一下:
首先,为Docker服务创建systemd drop-in目录:
mkdir /etc/systemd/system/docker.service.d
现在创建一个名为/etc/systemd/system/docker.service.d/http-proxy.conf的文件,其中添加了HTTP_PROXY和HTTPS_PROXY环境变量:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
Environment="HTTPS_PROXY=http://proxy.example.com:80/"
如果你有内部的Docker注册表,你可以通过NO_PROXY环境变量指定它们:
Environment="HTTP_PROXY=http://proxy.example.com:80/"
Environment="HTTPS_PROXY=http://proxy.example.com:80/"
Environment="NO_PROXY=localhost,127.0.0.0/8,docker-registry.somecorporation.com"
平的变化:
$ sudo systemctl daemon-reload
验证配置已经加载:
$ sudo systemctl show --property Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/
Environment=HTTPS_PROXY=http://proxy.example.com:80/
重启码头工人:
$ sudo systemctl restart docker
关于HTTP_PROXY vs. HTTPS_PROXY的脚注:很长一段时间以来,单独设置HTTP_PROXY已经足够好了。但是在20.10.8版本中,Docker已经迁移到Go 1.16,这改变了这个变量的语义:
https://golang.org/doc/go1.16#net/http
对于https:// url,代理现在由HTTPS_PROXY变量决定,在HTTP_PROXY上没有回退。