5-13 14 views
1. 背景
在需要通过代理才能上网的环境下,以下这个配置就显得尤为重要。
经过几翻测试下来发现docker并不会使用系统层面的HTTP_PROXY配置,需要对docker进行单独的配置
配置http代理有二种方法:
- /etc/docker/daemon.json
- /etc/systemd/system/docker.service.d/http-proxy.conf
一开始我是写到了daemon.json中,but始终无效,后来在官网上看到了这么一段话
2. 配置
2.1 创建 docker.service.d/http-proxy.conf和docker.service.d/https-proxy.conf 目录
1 2 3 4 5 6 |
eric@eric-ThinkPad-X270:~$ sudo mkdir -p /etc/systemd/system/docker.service.d/ eric@eric-ThinkPad-X270:~$ sudo touch /etc/systemd/system/docker.service.d/{http,https}-proxy.conf eric@eric-ThinkPad-X270:~$ tree /etc/systemd/system/docker.service.d/ /etc/systemd/system/docker.service.d/ ├── http-proxy.conf └── https-proxy.conf |
2.2 添加HTTP_PROXY配置
如果你是HTTP代理配置HTTP_PROXY
1 2 3 4 5 |
eric@eric-ThinkPad-X270:~$ sudo vim /etc/systemd/system/docker.service.d/http-proxy.conf ... [Service] Environment="HTTP_PROXY=http://192.168.31.148:808/" "NO_PROXY=localhost,127.0.0.1,hub.itnotebooks.com" ... |
如果你是HTTPS代理,配置HTTPS_PROXY
1 2 3 4 5 |
eric@eric-ThinkPad-X270:~$ sudo vim /etc/systemd/system/docker.service.d/https-proxy.conf ... [Service] Environment="HTTPS_PROXY=https://192.168.31.148:808/" "NO_PROXY=localhost,127.0.0.1,hub.itnotebooks.com" ... |
2.3 保存/刷新
1 2 |
eric@eric-ThinkPad-X270:~$ sudo systemctl daemon-reload eric@eric-ThinkPad-X270:~$ sudo systemctl restart docker |
2.4 查看配置
1 2 3 |
eric@eric-ThinkPad-X270:~$ sudo systemctl show --property=Environment docker Environment=HTTP_PROXY=http://192.168.31.148:808/ NO_PROXY=localhost,127.0.0.1,hub.itnotebooks.com" |
参考官网:https://docs.docker.com/config/daemon/systemd/
如果想赏钱,可以用微信扫描下面的二维码,一来能刺激我写博客的欲望,二来好维护云主机的费用; 另外再次标注博客原地址 itnotebooks.com 感谢!