原文: https://www.dadclab.com/archives/7638.jiecao

1. 创建通过systemd配置docker服务的文件夹

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

2. 创建服务配置文件

vim /etc/systemd/system/docker.service.d/http-proxy.conf

并将以下内容写入文件之中(根据你的实际情况,修改上述文件内容之中的代理信息)。

[Service]
 # NO_PROXY is optional and can be removed if not needed
 # Change proxy_url to your proxy IP or FQDN and proxy_port to your proxy port
 # For Proxy server which require username and password authentication, just add the proper username and password to the URL. (see example below)

 # Example without authentication
 Environment="HTTP_PROXY=http://proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"

 # Example with authentication
 Environment="HTTP_PROXY=http://username:password@proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"

3. 生效
使用如下命令重新加载systemctl, 验证服务环境变量并重启Docker服务。

# 重新加载systemctl 
systemctl daemon-reload
# 验证配置
systemctl show docker --property Environment
# 重启服务
system restart docker

标签: docker

添加新评论