22
0

ubuntu 临时设置代理 docker 设置代理

2026-08-01

1. HTTP/HTTPS 代理示例

# 替换你的代理地址 ip:port
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
export ALL_PROXY=http://127.0.0.1:7890
# 不代理本地、内网
export NO_PROXY=localhost,127.0.0.1,10.0.0.0/8,192.168.0.0/16,172.16.0.0/12

2. Socks5 代理示例(clash/v2ray 常用)

export HTTP_PROXY=socks5://127.0.0.1:7890
export HTTPS_PROXY=socks5://127.0.0.1:7890
export ALL_PROXY=socks5://127.0.0.1:7890
export NO_PROXY=localhost,127.0.0.1,10.0.0.0/8,192.168.0.0/16,172.16.0.0/12

3.取消当前终端临时代理

unset HTTP_PROXY HTTPS_PROXY ALL_PROXY NO_PROXY

4.【全局】Docker Daemon 代理


创建 docker 配置目录
bash
mkdir -p /etc/systemd/system/docker.service.d
创建代理配置文件
bash
nano /etc/systemd/system/docker.service.d/http-proxy.conf
写入内容(修改 IP 和端口)

[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,10.0.0.0/8,192.168.0.0/16,172.16.0.0/12"
重载 systemd、重启 docker
systemctl daemon-reload
systemctl restart docker
✅ 验证是否生效
systemctl show docker | grep -i proxy
❌ 删除全局代理(恢复无代理)
rm -f /etc/systemd/system/docker.service.d/http-proxy.conf
systemctl daemon-reload
systemctl restart docker

/

/

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或者给予支持!