Docker设置代理:docker pull 代理
方式一: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
docker docker代理 docker pull docker proxy
收到3条评论
森森 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"
}
}
```
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"
}
}
```
回复

myluzh 12 天前
@森森:也可以
回复
99 1 年前
作者这个很有用
回复