我们国家的网络大家是知道的,经常timeout,多亏了方校长。
一般的方法是添加 http_proxy的环境变量,
然而这一招在docker pull image 的时候并不起作用。
因为拉镜像的时候是dockerd在拉镜像,因此要添加代理必须在dockerd上想办法。
docker 官方已经贴心地为各们小主们想好了办法:
Control Docker with systemd | Docker Documentation
-
Create a systemd drop-in directory for the docker service:
$ sudo mkdir -p /etc/systemd/system/docker.service.d
-
Create a file named
/etc/systemd/system/docker.service.d/http-proxy.conf
that adds theHTTP_PROXY
environment variable:[Service] Environment="HTTP_PROXY=http://proxy.example.com:80"
If you are behind an HTTPS proxy server, set the
HTTPS_PROXY
environment variable:[Service] Environment="HTTPS_PROXY=https://proxy.example.com:443"
Multiple environment variables can be set; to set both a non-HTTPS and a HTTPs proxy;
[Service] Environment="HTTP_PROXY=http://proxy.example.com:80" Environment="HTTPS_PROXY=https://proxy.example.com:443"
-
If you have internal Docker registries that you need to contact without proxying you can specify them via the
NO_PROXY
environment variable.The
NO_PROXY
variable specifies a string that contains comma-separated values for hosts that should be excluded from proxying. These are the options you can specify to exclude hosts:- IP address prefix (
1.2.3.4
) - Domain name, or a special DNS label (
*
) - A domain name matches that name and all subdomains. A domain name with a leading “.” matches subdomains only. For example, given the domains
foo.example.com
andexample.com
:example.com
matchesexample.com
andfoo.example.com
, and.example.com
matches onlyfoo.example.com
- A single asterisk (
*
) indicates that no proxying should be done - Literal port numbers are accepted by IP address prefixes (
1.2.3.4:80
) and domain names (foo.example.com:80
)
Config example:
[Service] Environment="HTTP_PROXY=http://proxy.example.com:80" Environment="HTTPS_PROXY=https://proxy.example.com:443" Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp"
- IP address prefix (
-
Flush changes and restart Docker
$ sudo systemctl daemon-reload $ sudo systemctl restart docker
-
Verify that the configuration has been loaded and matches the changes you made, for example:
$ sudo systemctl show --property=Environment docker
基本就这样。
英文比较简单。大家都能看懂。
bishi 一些国人
docker如何设置HTTP代理-Docker-PHP中文网
翻译的不怎么的,还强翻。 误人子弟。