在 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 上设置代理。如果你有任何问题或者建议,欢迎在下方留言。

相关推荐
bloglin999998 小时前
启动容器报错ls: cannot access ‘/docker-entrypoint-initdb.d/‘: Operation not permitted
docker·容器·eureka
yBmZlQzJ10 小时前
免费内网穿透-端口转发配置介绍
运维·经验分享·docker·容器·1024程序员节
JH307310 小时前
docker 新手入门:10分钟搞定基础使用
运维·docker·容器
天河归来12 小时前
在本地windows电脑使用Docker搭建xinference环境
docker·语言模型·容器
算力魔方AIPC13 小时前
使用 Docker 一键部署 PaddleOCR-VL: 新手保姆级教程
运维·docker·容器
Ghost Face...14 小时前
Docker实战:从安装到多容器编排指南
运维·docker·容器
TSAI15 小时前
Docker Swarm 集群部署 Eureka 服务注册中心:高可用微服务架构的基石
spring cloud·docker
不惑_15 小时前
Windows 安装 Docker 和 Docker Compose 完整教程
windows·docker·容器
jcsx16 小时前
如何将django项目发布为https
python·https·django
Neolnfra16 小时前
渗透测试标准化流程
开发语言·安全·web安全·http·网络安全·https·系统安全