在 Docker Desktop 上设置 HTTP/HTTPS/SOCKS5 代理
在使用 Docker Desktop 时,可能会遇到需要通过代理服务器访问外部网络的情况。本篇博客将会介绍如何在 Linux、Windows 以及 MacOS 上的 Docker Desktop 设置 HTTP/HTTPS 以及 SOCKS5 代理。
在 Linux 上设置代理
在 Linux 上,你可以通过环境变量来为 Docker 设置代理。你需要在 /usr/lib/systemd/system/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
Environment="HTTP_PROXY=socks5://x.x.x.x:xxxx"
Environment="HTTPS_PROXY=socks5://x.x.x.x:xxxx"
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
其中Environment=xxx
两句就需要添加的内容。
然后,你需要重新加载 systemd 配置并重启 Docker:</