我正在尝试使用Docker在公司代理服务器后面建立开发环境。尝试尝试,我无法使Docker容器与代理服务器通信。
代理服务器和apt-get在主机(Ubuntu 12.04)上可以正常工作
Dockerfile中要做的第一件事就是尝试设置代理变量:
FROM ubuntu
RUN echo 'Acquire::http { Proxy "http://my.proxy.net:8000"; };' >> /etc/apt/apt.conf.d/01proxy
ENV HTTP_PROXY http://my.proxy.net:8000
ENV http_proxy http://my.proxy.net:8000
ENV HTTPS_PROXY https://my.proxy.net:8000
ENV https_proxy https://my.proxy.net:8000
RUN apt-get update && apt-get install -y build-essential
它可以很好地处理图像,设置变量,但是当要进行apt-get update时,它会尝试一段时间,然后失败,并显示以下信息:
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/InRelease
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg Could not resolve 'my.proxy.net'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg Could not resolve 'my.proxy.net'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg Could not resolve 'my.proxy.net'
W: Some index files failed to download. They have been ignored, or old ones used instead.
我设置的这些变量与主机linux安装(如果重要的话,在VirtualBox上使用Ubuntu 12.04)一致
我还用以下命令设置了/ etc / default / docker:
export http_proxy="http://my.proxy.net:8000"
export http_proxy="https://my.proxy.net:8000"
有什么想法吗?
更新:
看起来这是DNS的问题,不一定是代理服务器。主机/etc/resolve.conf包含:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1
search dhcp.mycompany.com
主机是在Windows 7机器上运行的virtualbox虚拟机,我发现了各种半熟的解决方案,这些解决方案似乎大部分都不起作用。无论我尝试什么,都无法解析代理服务器的主机名
问题最终与DNS有关。Docker在Ubuntu上运行,而Ubuntu本身就是VirtualBox上的Guest OS。由于它本身具有巨大的活力,因此在resolv.conf中为其分配了127.0.0.1的名称服务器。
发生这种情况时,Docker将为自己分配8.8.8.8的DNS名称服务器(谷歌的名称服务器),因为localhost是指Docker容器而不是主机。
为了解决这个问题,我一直使用Windows并运行
ipconfig /all
并获得了我的笔记本电脑DNS服务器的IP地址。我使用--dns = my.dns.ip.address将它们添加到配置文件中的DOCKER_OPTS中,并重新启动了docker,而我通过代理获得的其他措施也可以正常工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句