我正在尝试使用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机器上运行的虚拟机vm,我发现了大多数似乎不起作用的各种半生不熟的解决方案.无论我尝试什么,我都无法解决代理服务器的主机名
问题最终出现在DNS上. Docker在Ubuntu上运行,Ubuntu本身就是VirtualBox上的Guest OS.由于它自己的虚拟版mumbo jumbo,它在resolv.conf中分配了一个127.0.0.1的名称服务器.
原文链接:https://www.f2er.com/docker/436443.html发生这种情况时,Docker将为自己分配一个8.8.8.8(谷歌名称服务器)的DNS名称服务器,因为localhost引用的是docker容器而不是主机.
为了解决这个问题,我一直走到Windows并跑了
ipconfig /all
并获得我的笔记本电脑DNS服务器的IP地址.我使用–dns = my.dns.ip.address将这些添加到配置文件中的DOCKER_OPTS并重新启动了docker,我通过代理所采取的其他措施运行正常.