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

我做错了什么?


当前回答

如果使用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, Docker版本:1.6.2

在/etc/default/docker文件中,添加一行:

export http_proxy='http://<host>:<port>'

重启码头工人

sudo service docker restart

在防火墙后面,我也面临着同样的问题。请遵循以下步骤:

$ sudo vim /etc/systemd/system/docker.service.d/http_proxy.conf
[Service]
Environment="HTTP_PROXY=http://username:password@IP:port/"

不要使用或删除https_prxo .conf文件。

重新加载并重新启动Docker容器:

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557*********************************8
Status: Downloaded newer image for hello-world:latest

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

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

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

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

service docker restart

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

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

为什么本地绑定代理不起作用

这个问题

如果你正在运行一个本地绑定的代理,例如监听127.0.0.1:8989,它将不会在Docker for Mac中工作。

我想从容器连接到主机上的服务 Mac有一个不断变化的IP地址(如果没有网络访问,则没有)。我们目前的建议是将一个未使用的IP附加到Mac上的lo0接口;例如:sudo ifconfig lo0 alias 10.200.10.1/24,并确保您的服务监听该地址或0.0.0.0(即不是127.0.0.1)。然后容器就可以连接到这个地址。

Docker服务器端也是如此。(为了了解Docker的服务器端和客户端,请尝试运行Docker版本。)服务器端运行在具有自己本地主机的虚拟化层上。因此,它不会连接到主机操作系统的localhost上的代理服务器。

解决方案

所以,如果你像我一样使用本地绑定代理,基本上你必须做以下事情才能使它与Mac的Docker一起工作:

让代理服务器监听0.0.0.0而不是127.0.0.1。警告:您需要适当的防火墙配置,以防止恶意访问。 为lo0接口添加一个环回别名,例如10.200.10.1/24: Sudo ifconfig lo0 alias 10.200.10.1/24 从Docker托盘菜单中的Preferences中将HTTP和/或HTTPS代理设置为10.200.10.1:8989(假设代理服务器正在监听端口8989)。

在这之后,通过在一个没有下载的镜像中运行一个命令来测试代理设置:

$ docker rmi -f hello-world
  ...

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

c04b14da8d14: Pull complete 
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Status: Downloaded newer image for hello-world:latest
  ...

注意:ifconfig设置的环回别名在重启后将不保留。让它持久是另一个主题。请查看这篇日文博客文章(谷歌翻译可能有帮助)。