Ubuntu下为docker设置代理

王锐
王锐
发布于 2024-09-20 / 80 阅读
0
3

Ubuntu下为docker设置代理

安装docker后,需要配置代理才能解决pull容器下载,

一共有两种方式

方式一:配置docker.service

具体详情如下:参考: https://cloud.tencent.com/developer/article/1806455

sudo vim /etc/systemd/system/multi-user.target.wants/docker.service
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
[+++]Environment="HTTP_PROXY=http://127.0.0.1:21080/"
[+++]Environment="HTTPS_PROXY=http://127.0.0.1:21080/"
[+++]Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

方式二:

创建代理配置文件:

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

修改文件内容

[Service]
Environment="HTTP_PROXY=http://192.168.1.100:7890/"
Environment="HTTPS_PROXY=http://192.168.1.100:7890/"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.some.internal"

加载并重启

sudo systemctl daemon-reload
sudo systemctl restart docker


评论