Cannot download Docker images behind a proxy

2019-01-01 06:20发布

I installed Docker on my Ubuntu 13.10 (Saucy Salamander) and when I type in my console:

sudo docker pull busybox

I get the following error:

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 version:

$ 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

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

What am I doing wrong?

标签: proxy docker
22条回答
栀子花@的思念
2楼-- · 2019-01-01 06:27

Your APT proxy settings are not related to Docker.

Docker uses the HTTP_PROXY environment variable if present, for example:

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

But instead, I suggest you have a look at your /etc/default/dockerconfiguration file : you should have a line to uncomment (and maybe adjust) to get your proxy settings applied automatically. Then restart the Docker server:

service docker restart
查看更多
深知你不懂我心
3楼-- · 2019-01-01 06:27

To extend Arun's answer above, for this to work in CentOS 7, I had to remove the "export" commands. So edit

/etc/sysconfig/docker

And add:

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

Then restart Docker:

sudo service docker restart

The source is this blog post.

查看更多
浪荡孟婆
4楼-- · 2019-01-01 06:27

After installing Docker, do the following:

[mdesales@pppdc9prd1vq ~]$ sudo HTTP_PROXY=http://proxy02.ie.xyz.net:80 ./docker -d &
[2] 20880

Then, you can pull or do anything:

mdesales@pppdc9prd1vq ~]$ sudo docker pull base
2014/04/11 00:46:02 POST /v1.10/images/create?fromImage=base&tag=
[/var/lib/docker|aa088847] +job pull(base, )
Pulling repository base
b750fe79269d: Download complete
27cf78414709: Download complete
[/var/lib/docker|aa088847] -job pull(base, ) = OK (0)
查看更多
不流泪的眼
5楼-- · 2019-01-01 06:29

Here is a link to the official Docker documentation for proxy HTTP: https://docs.docker.com/config/daemon/systemd/#httphttps-proxy

A quick outline:

First, create a systemd drop-in directory for the Docker service:

mkdir /etc/systemd/system/docker.service.d

Now create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"

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="NO_PROXY=localhost,127.0.0.0/8,docker-registry.somecorporation.com"

Flush changes:

$ sudo systemctl daemon-reload

Verify that the configuration has been loaded:

$ sudo systemctl show --property Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/

Restart Docker:

$ sudo systemctl restart docker
查看更多
路过你的时光
6楼-- · 2019-01-01 06:29

Perhaps you need to set up lowercase variables. In my case, my /etc/systemd/system/docker.service.d/http-proxy.conf file is look like this:

[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>/"

Good luck! :)

查看更多
何处买醉
7楼-- · 2019-01-01 06:29

If using socks5 proxy, here is my test with Docker 17.03.1-ce with setting "all_proxy", and it worked:

# 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
查看更多
登录 后发表回答