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

我做错了什么?


当前回答

您的APT代理设置与Docker无关。

Docker使用HTTP_PROXY环境变量(如果存在)。例如:

sudo HTTP_PROXY=http://192.168.1.1:3128/ docker pull busybox

但是,我建议您查看一下您的/etc/default/dockerconfiguration文件:您应该有一行来取消注释(可能还会进行调整)以自动应用代理设置。然后重新启动Docker服务器:

service docker restart

其他回答

如果使用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

在Ubuntu 14.04 (Trusty Tahr)和Docker 1.9.1上,我只是取消了http_proxy行注释,更新了值,然后重新启动Docker服务。

export http_proxy="http://proxy.server.com:80"

然后

service docker restart

这并不能完全回答问题,但可能会有所帮助,特别是如果您不想处理服务文件的话。

如果您是托管映像的人,一种方法是将映像转换为tar存档,在服务器上使用类似以下的东西。

docker save <image-name> --output <archive-name>.tar

只需下载存档并将其转换回图像即可。

docker load <archive-name>.tar

按照以下步骤解决问题:

步骤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

为了解决Docker构建中的curl问题,我在Dockerfile中添加了以下内容:

ENV http_proxy=http://infoprx2:8080
ENV https_proxy=http://infoprx2:8080
RUN apt-get update && apt-get install -y curl vim

注意,ENV语句在RUN语句之前。

为了使Docker守护进程能够访问Internet(我使用Kitematic和boot2docker),我在/var/lib/boot2docker/profile中添加了以下内容:

export HTTP_PROXY=http://infoprx2:8080
export HTTPS_PROXY=http://infoprx2:8080

然后我用sudo /etc/init.重启Dockerd /码头工人重新启动。