无法在代理后下载 Docker 映像
我在 Ubuntu 13.10 (Saucy Salamander) 上安装了 Docker,当我在控制台中输入时:
I installed Docker on my Ubuntu 13.10 (Saucy Salamander) and when I type in my console:
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
Docker 版本:
$ 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
文件:
I am behind a proxy server with no authentication, and this is my /etc/apt/apt.conf
file:
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/";
我做错了什么?
这里是代理 HTTP 的官方 Docker 文档的链接:https://docs.docker.com/config/daemon/systemd/#httphttps-代理
Here is a link to the official Docker documentation for proxy HTTP: https://docs.docker.com/config/daemon/systemd/#httphttps-proxy
简要概述:
首先,为 Docker 服务创建一个 systemd 插入目录:
First, create a systemd drop-in directory for the Docker service:
mkdir /etc/systemd/system/docker.service.d
现在创建一个名为 /etc/systemd/system/docker.service.d/http-proxy.conf
的文件,其中添加了 HTTP_PROXY
和 HTTPS_PROXY
环境变量:
Now create a file called /etc/systemd/system/docker.service.d/http-proxy.conf
that adds the HTTP_PROXY
and HTTPS_PROXY
environment variables:
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"
Environment="HTTPS_PROXY=http://proxy.example.com:80/"
如果您有内部 Docker 注册表需要联系而无需代理,您可以通过 NO_PROXY
环境变量指定它们:
If you have internal Docker registries that you need to contact without proxying you can specify them via the NO_PROXY
environment variable:
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/
重启 Docker:
$ sudo systemctl restart docker
关于HTTP_PROXY
与HTTPS_PROXY
的脚注:长期以来,单独设置HTTP_PROXY
已经足够好了.但是在 20.10.8 版本中,Docker 已经转移到 Go 1.16,它改变了这个变量的语义:https://golang.org/doc/go1.16#net/http
对于 https://
网址,代理现在由 HTTPS_PROXY
变量确定,HTTP_PROXY
没有后备.
Footnote regarding HTTP_PROXY
vs. HTTPS_PROXY
: for a long time, setting HTTP_PROXY
alone has been good enough. But with version 20.10.8, Docker has moved on to Go 1.16, which changes the semantics of this variable:
https://golang.org/doc/go1.16#net/http
For https://
URLs, the proxy is now determined by the HTTPS_PROXY
variable, with no fallback on HTTP_PROXY
.