«

Docker设置代理:docker pull 代理

myluzh 发布于 阅读:893 Docker


方式一:daemon.json (推荐)

Daemon configuration
You may configure proxy behavior for the daemon in the daemon.json file, or using CLI flags for the --http-proxy or --https-proxy flags for the dockerd command. Configuration using daemon.json is recommended.

{
  "proxies": {
    "http-proxy": "http://proxy.example.com:3128",
    "https-proxy": "https://proxy.example.com:3129",
    "no-proxy": "*.test.example.com,.example.org,127.0.0.0/8"
  }
}

After changing the configuration file, restart the daemon for the proxy configuration to take effect: sudo systemctl restart docker
参考文章:https://docs.docker.com/engine/daemon/proxy/

方式二:systemd 环境变量

docker pull /push 的代理被 systemd 接管,所以需要设置 systemd

mkdir -p /etc/systemd/system/docker.service.d
touch /etc/systemd/system/docker.service.d/proxy.conf
vi /etc/systemd/system/docker.service.d/proxy.conf

编辑proxy.conf文件

# proxy.conf
[Service]
Environment="HTTP_PROXY=http://172.30.172.136:4780"
Environment="HTTPS_PROXY=http://172.30.172.136:4780"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com,172.16.0.0/12"

重启docker服务

sudo systemctl daemon-reload
sudo systemctl restart docker
# 可以看到设置的环境变量
sudo systemctl show docker | grep Environment

参考文章:https://neucrack.com/p/286

docker docker代理 docker pull docker proxy


正文到此结束
版权声明:若无特殊注明,本文皆为 Myluzh Blog 原创,转载请保留文章出处。
文章内容:https://itho.cn/docker/481.html
文章标题:《Docker设置代理:docker pull 代理
收到3条评论
avatar
森森 1 个月前
官方推荐的方式是:

Edit or create the /etc/docker/daemon.json file and add your proxy settings:

```json
{
  "proxies": {
    "http-proxy": "http://proxy.example.com:3128",
    "https-proxy": "https://proxy.example.com:3129",
    "no-proxy": "*.test.example.com,.example.org,127.0.0.1"
  }
}
```
回复
commentator
myluzh 12 天前
@森森:也可以
回复
avatar
99 1 年前
作者这个很有用
回复