无法在dockerfile

时间:2017-10-11 04:23:14

标签: docker proxy firewall

我无法在公司防火墙后面运行Docker "Getting started" example。它在没有防火墙的情况下在家中运行良好。

当我使用docker build -t my_tag .构建图像时,它在尝试安装某些python包时失败。 docker文件具有以下命令:

RUN pip install -r requirements.txt

错误消息是:

  

收集Redis(来自-r requirements.txt(第1行))重试   (重试(total = 4,connect = None,read = None,redirect = None))之后   连接被'ProxyError('无法连接到代理'。)所破坏,   NewConnectionError(':无法建立新连接:   [Errno -2]名称或服务未知',))':/ simple / redis /

我尝试在dockerfile中设置代理(各种格式,但它们都失败了):

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

我尝试在/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 .

我在Linux mint上使用docker版本1.12.6运行它。

有人有什么想法吗?

更新1: 如果我简化dockerfile所以它使用curl(没有python或pip)

FROM ubuntu
WORKDIR /app
ADD . /app
EXPOSE 80

# Define environment variable
ENV http_proxy=http://my_username:my_password@my_host:80
ENV https_proxy=http://my_username:my_password@my_host:80
ENV HTTP_PROXY=http://my_username:my_password@my_host:80
ENV HTTPS_PROXY=http://my_username:my_password@my_host:80

RUN apt-get -qq update
RUN apt-get -qq -y install curl

CMD ["curl www.google.com.au"]

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

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”是正确的代理(BTW我测试了这个,用户名/密码/代理主机名确实有效)

更新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 .

错误仍为Temporary failure resolving '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

2 个答案:

答案 0 :(得分:0)

如果您在正常环境中有代理集(意味着在Docker构建中没有,但对于您的主机操作系统),请仔细检查其unsigned c_tolower (unsigned c) { if ('A' <= c && c <= 'Z') c ^= (1 << 5); return c; } 值。

https_proxy网址应与https_proxy网址相同:它应以http_proxy开头。
http

首先在简化的Dockerfile(例如https)中进行简单测试 然后,另请参阅pip issue 1805,其中显示curl www.google.com如何使用代理。

答案 1 :(得分:0)

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

请参阅the description here