Can';t在dockerfile中设置代理

Can';t在dockerfile中设置代理,docker,proxy,firewall,Docker,Proxy,Firewall,我不能在公司防火墙后运行Docker。它在家里运行良好,没有防火墙 当我使用docker build-t my_标记构建映像时。,它在尝试安装一些python包时失败。docker文件具有以下命令: RUN pip install -r requirements.txt 错误消息是: cat: /etc/resolve.conf: No such file or directory The command '/bin/sh -c cat /etc/resolve.conf' returned

我不能在公司防火墙后运行Docker。它在家里运行良好,没有防火墙

当我使用
docker build-t my_标记构建映像时。
,它在尝试安装一些python包时失败。docker文件具有以下命令:

RUN pip install -r requirements.txt
错误消息是:

cat: /etc/resolve.conf: No such file or directory
The command '/bin/sh -c cat /etc/resolve.conf' returned a non-zero code: 1
正在收集Redis(从-r requirements.txt(第1行))重试 (重试(总计=4,连接=None,读取=None,重定向=None))之后 连接被“ProxyError”(“无法连接到代理”)中断, NewConnectionError(':未能建立新连接: [Errno-2]名称或服务未知',)':/simple/redis/

我曾尝试在dockerfile中设置代理(使用各种格式,但都失败):

我已尝试在文件/etc/systemd/system/docker.service.d/http-proxy.conf中设置环境:

[Service]
Environment="HTTP_PROXY=http://my_username:my_password@my_host:80/" "HTTPS_PROXY=https://my_username:my_password@my_host:80/"
我已尝试更改dockerfile中的
RUN pip install
命令,以便它还包括代理:

RUN pip install --proxy="my_username:my_password@my_host:80" -r requirements.txt
我已尝试在/etc/default/docker中设置选项,添加:

DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
我已尝试将代理添加到docker build命令:

docker build -t python_example_1 --build-arg HTTPS_PROXY=https://my_username:my_password@my_host:80 --build-arg HTTP_PROXY=http://my_username:my_password@my_host:80 .
我在LinuxMint上运行Docker1.12.6版

有人有什么想法吗


更新1: 如果我简化dockerfile,使其使用curl(无python或pip)

错误消息表明它正在获取代理信息,但存在某种名称解析问题:

Removing intermediate container 945f8123da61
Step 10 : RUN apt-get -qq update
 ---> Running in 99a5bbbb943d
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease  Temporary failure resolving 'my_host'
其中“my_host”是正确的代理(顺便说一句,我已经测试过了,用户名/密码/代理主机名确实有效)


更新2 如果我从docker文件中删除ENV,那么它现在是:

FROM ubuntu
WORKDIR /app
ADD . /app
EXPOSE 80

ARG http_proxy=http://my_username:my_password@my_host:80
ARG https_proxy=http://my_username:my_password@my_host:80
ARG HTTP_PROXY=http://my_username:my_password@my_host:80
ARG HTTPS_PROXY=http://my_username:my_password@my_host:80

RUN apt-get -qq update
并使用--build args进行生成:

docker build --build-arg HTTPS_PROXY=http://my_username:my_password@my_host:80 --build-arg HTTP_PROXY=http://my_username:my_password@my_host:80 .
错误仍然是
临时故障解析'archive.ubuntu.com'

如果我试图通过将其放入docker文件来添加名称服务器:

RUN echo "nameserver 8.8.8.8" >> /etc/resolv.conf
RUN cat /etc/resolve.conf
错误消息是:

cat: /etc/resolve.conf: No such file or directory
The command '/bin/sh -c cat /etc/resolve.conf' returned a non-zero code: 1
可能这不起作用,因为它正在“中间容器”中创建/etc/resolv.conf文件,而在下一步中不可用?。较长的输出为:

Removing intermediate container 1f77c03ee8be
Step 5 : RUN echo "nameserver 8.8.8.8" >> /etc/resolv.conf
 ---> Running in e2a9717f6bed
 ---> 13752a04094b
Removing intermediate container e2a9717f6bed
Step 6 : RUN cat /etc/resolve.conf
 ---> Running in 94ce4a72867b
cat: /etc/resolve.conf: No such file or directory

如果在您的正常环境中设置了代理(在docker构建中表示否,但对于您的主机操作系统而言),请仔细检查其
https\u proxy

https\u代理
URL应该与
http\u代理
相同:它应该以
http
开头
https

首先在简化的Dockerfile中做一个简单的测试(
curl www.google.com


然后,另请参见其中显示的
pip
如何使用代理。

解决方案是将DNS条目添加到/etc/docker/daemon.json


请参见

感谢您的支持alkdj@John不客气。不要忘记阅读(关于这个问题或你过去的其他问题)对不起,我对这个问题不熟悉。我想用你的建议来更新我的问题,试试卷发。我尝试了curl并用更新编辑了我的问题(不确定这样做是否正确-我看不出如何“回复”根据你的建议。@John建议
curl www.google.com.au
我的意思不是CMD,而是一个简单的运行,在构建过程中查看输出。实际上,你的
apt get-qq update
本身就是一个很好的测试:只要它不起作用,其他与互联网相关的东西都不会起作用。@John尝试删除你的ENV行,添加两个ARG()行:
ARG http_proxy
ARG https_proxy
。然后使用
--build args
参数进行
docker build
(以及使用http URL的
https_proxy
Removing intermediate container 1f77c03ee8be
Step 5 : RUN echo "nameserver 8.8.8.8" >> /etc/resolv.conf
 ---> Running in e2a9717f6bed
 ---> 13752a04094b
Removing intermediate container e2a9717f6bed
Step 6 : RUN cat /etc/resolve.conf
 ---> Running in 94ce4a72867b
cat: /etc/resolve.conf: No such file or directory