在 Docker Desktop 上设置 HTTP/HTTPS/SOCKS5 代理

在 Docker Desktop 上设置 HTTP/HTTPS/SOCKS5 代理

在使用 Docker Desktop 时,可能会遇到需要通过代理服务器访问外部网络的情况。本篇博客将会介绍如何在 Linux、Windows 以及 MacOS 上的 Docker Desktop 设置 HTTP/HTTPS 以及 SOCKS5 代理。

在 Linux 上设置代理

在 Linux 上,你可以通过环境变量来为 Docker 设置代理。你需要在 /usr/lib/systemd/system/docker.service 文件中添加环境变量:

txt 复制代码
[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:

console 复制代码
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

在 Windows 上设置代理

在 Windows 上,你可以通过 Docker Desktop 的图形界面来设置代理。首先,打开 Docker Desktop,然后选择 Settings > Proxies,在这里,你可以设置 HTTP/HTTPS 代理,也可以设置 SOCKS5 代理。

例如,你可以在 HTTP Proxy 字段中输入 http://proxy.example.com:80,在 HTTPS Proxy 字段中输入 https://proxy.example.com:443

socks5代理需要企业订阅(要花钱)

最后,点击 Apply & Restart 按钮来应用设置并重启 Docker。

在 MacOS 上设置代理

在 MacOS 上,你也可以通过 Docker Desktop 的图形界面来设置代理。首先,打开 Docker Desktop,然后选择 Preferences > Proxies,在这里,你可以设置 HTTP/HTTPS 代理,也可以设置 SOCKS5 代理。

例如,你可以在 HTTP Proxy 字段中输入 http://proxy.example.com:80,在 HTTPS Proxy 字段中输入 https://proxy.example.com:443,然后在 No Proxy 字段中输入 localhost,127.0.0.1,。

socks5代理需要企业订阅(要花钱)

最后,点击 Apply & Restart 按钮来应用设置并重启 Docker。

希望这篇文章能够帮助你理解如何在 Docker Desktop 上设置代理。如果你有任何问题或者建议,欢迎在下方留言。

相关推荐
fetasty9 小时前
rustfs加picgo图床搭建
docker
小时前端9 小时前
HTTPS 页面加载 HTTP 脚本被拦?同源代理来救场
前端·https
蝎子莱莱爱打怪1 天前
GitLab CI/CD + Docker Registry + K8s 部署完整实战指南
后端·docker·kubernetes
不可能的是1 天前
前端 SSE 流式请求三种实现方案全解析
前端·http
小p2 天前
docker学习7:docker 容器的通信方式
docker
小p2 天前
docker学习5:提升Dockerfile水平的5个技巧
docker
小p2 天前
docker学习3:docker是怎么实现的?
docker
小p3 天前
docker学习: 2. 构建镜像Dockerfile
docker
小p4 天前
docker学习: 1. docker基本使用
docker
崔小汤呀4 天前
Docker部署Nacos
docker·容器