我在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/";

我做错了什么?


当前回答

从环境变量中删除代理

unset http_proxy
unset https_proxy
unset no_proxy

然后重新启动docker

其他回答

为了扩展Arun的回答,让它在CentOS 7中工作,我必须删除“导出”命令。所以编辑

/etc/sysconfig/docker

并添加:

HTTP_PROXY="http://<proxy_host>:<proxy_port>"
HTTPS_PROXY="https://<proxy_host>:<proxy_port>"
http_proxy="${HTTP_PROXY}"
https_proxy="${HTTPS_PROXY}"

然后重启Docker:

sudo service docker restart

来源是这篇博客文章。

也许你需要设置小写变量。在我的例子中,我的/etc/systemd/system/docker.service.d/http-proxy.conf文件看起来像这样:

[Service]
Environment="ftp_proxy=http://<user>:<password>@<proxy_ip>:<proxy_port>/"
Environment="http_proxy=http://<user>:<password>@<proxy_ip>:<proxy_port>/"
Environment="https_proxy=http://<user>:<password>@<proxy_ip>:<proxy_port>/"

好运!:)

在Ubuntu上,你需要为Docker守护进程设置http_proxy,而不是客户端进程。这是在/etc/default/docker中完成的(参见这里)。

如果使用socks5代理,下面是我在Docker 17.03.1-ce中设置“all_proxy”的测试,它是有效的:

# Set up socks5 proxy server
ssh sshUser@proxyServer -C -N -g -D \
     proxyServerIp:9999 \
     -o ExitOnForwardFailure=yes \
     -o ServerAliveInterval=60

# Configure dockerd and restart.
# NOTICE: using "all_proxy"
mkdir -p /etc/systemd/system/docker.service.d
cat > /etc/systemd/system/docker.service.d/http-proxy.conf <<EOF
[Service]
Environment="all_proxy=socks5://proxyServerIp:9999"
Environment="NO_PROXY=localhost,127.0.0.1,private.docker.registry.com"
EOF

systemctl daemon-reload
systemctl restart docker

# Test whether can pull images
docker run -it --rm alpine:3.5

在Docker的新版本中,Docker -engine,在一个基于systemd的发行版中,你应该在/lib/systemd/system/ Docker中添加环境变量line。服务,正如其他人所提到的:

Environment="HTTP_PROXY=http://hostname_or_ip:port/"