首页 > 解决方案 > 通过 Oracle VM 和 cntlm 代理从 docker 内部访问 Internet

问题描述

如何在 Ubuntu 16.04 上通过 Oracle VM (5.2.4) 和 Windows 7 上的 cntlm 代理从 docker 内部进行 Internet http 调用?

代理已配置(IP 192.168.56.1,VM 主机)。在 Ubuntus Firefox 中或使用命令行中的 wget 可以成功访问 Internet。

Docker CE (17.12.0-ce) 配置为也使用代理 ip:/etc/systemd/system/docker.service.d/http-proxy.conf

[Service]
Environment="HTTP_PROXY=http://192.168.56.1:3128/"
Environment="HTTPS_PROXY=http://192.168.56.1:3128/"

我可以成功提取的所有 docker 图像。

只有 docker 容器内的 wget 或任何安装调用失败。

许多帮助页面稍后,我不知道更多。我的尝试:

docker run --name test --network host -e "https_proxy=https://192.168.56.101:3128" -it alpine:latest wget https://www.web.de
wget: bad address 'www.web.de'

docker run --name test --dns 8.8.8.8 -e "https_proxy=https://192.168.56.101:3128" -it alpine:latest wget https://www.web.de
wget: bad address 'www.web.de'

docker run --name test -e "https_proxy=https://192.168.56.101:3128" -it alpine:latest wget https://www.web.de
wget: bad address 'www.web.de'

docker run --name test --network host --dns 8.8.8.8 -e "https_proxy=https://192.168.56.101:3128" -it alpine:latest wget https://www.web.de
wget: bad address 'www.web.de'

所有打印的调用也带有“http”并且没有代理环境。

对我的另一个想法?

标签: dockerproxyvirtualboxubuntu-16.04

解决方案


For docker to work with CNTLM it is important to set

Gateway yes

in the CNTLM-Config.

I run CNTLM directly on the VM and set all proxys within the container to http://172.17.0.1:3128.

For the sake of completeness, please set all Proxy-Env in docker run:

PROXY_DOCKER="http://172.17.0.1:3128/"
docker run -e HTTP_PROXY=${PROXY_DOCKER} -e http_proxy=${PROXY_DOCKER} -e HTTPS_PROXY=${PROXY_DOCKER} -e https_proxy=${PROXY_DOCKER} ...

推荐阅读