如果宿主机访问外网依赖代理(比如 http_proxy
环境变量),容器默认不会继承。需要显式传入代理:
bash
docker run -e http_proxy=... -e https_proxy=... ...
在 docker-compose 中配置 HTTP/HTTPS 代理
bash
version: '3'
services:
app:
image: your_image
environment:
- http_proxy=http://proxy_ip:port
- https_proxy=http://proxy_ip:port
- no_proxy=localhost,127.0.0.1,.yourdomain.com