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

我做错了什么?


当前回答

如果你使用的是Ubuntu,执行这些命令来添加代理。

sudo nano /etc/default/docker

并取消指定的行注释

#export http_proxy = http://username:password@10.0.1.150:8050

并将其替换为适当的代理服务器和用户名。

然后使用以下命令重新启动Docker:

service docker restart

现在你可以在代理后运行Docker命令:

docker search ubuntu

其他回答

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

$ 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

如果你正在使用新的Mac Docker(或Windows Docker),只需右键单击Docker托盘图标,选择首选项(Windows:设置),然后进入高级,在代理下面指定代理设置。单击“应用并重新启动”,等待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

来源是这篇博客文章。

要配置Docker与代理一起工作,您需要将HTTPS_PROXY / HTTP_PROXY环境变量添加到Docker的sysconfig文件(/etc/sysconfig/ Docker)中。

取决于你是否使用init。d或服务工具,您需要添加“export”语句(由于Debian Bug报告日志- #767441. d)。/etc/default/docker中的示例在支持的语法方面具有误导性):

HTTPS_PROXY="https://<user>:<password>@<proxy-host>:<proxy-port>"
HTTP_PROXY="https://<user>:<password>@<proxy-host>:<proxy-port>"
export HTTP_PROXY="https://<user>:<password>@<proxy-host>:<proxy-port>"
export HTTPS_PROXY="https://<user>:<password>@<proxy-host>:<proxy-port>"

Docker存储库(Docker Hub)只支持HTTPS。要让Docker使用SSL拦截代理,您必须将代理根证书添加到系统信任存储区。

对于CentOS系统,将文件复制到/etc/pki/ca-trust/source/anchors/,更新CA信任库并重启Docker服务。

如果您的代理使用NTLMv2身份验证,则需要使用Cntlm等中间代理来桥接身份验证。这篇博客文章详细解释了这一点。

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

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

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

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

service docker restart