Docker构建错误:“无法连接到服务器” (在代理后面) [英] Docker build error: "could not connect to server" (behind proxy)

查看:504
本文介绍了Docker构建错误:“无法连接到服务器” (在代理后面)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:
操作系统:Windows 10 Pro; Docker版本:18.09.0(内部版本4d60db4);在公司代理的后面,使用CNTLM解决此问题。 (当前拉/运行映像工作正常)

Context: OS: Windows 10 Pro; Docker ver: 18.09.0 (build 4d60db4); Behind corporate proxy, using CNTLM to solve this issue. (currently pulling / running image works fine)

问题:
我正在尝试构建以下Dockerfile:

Problem: I was trying to build the following Dockerfile:

FROM alpine:3.5
RUN apk add --update \
    python3
RUN pip3 install bottle
EXPOSE 8000
COPY main.py /main.py
CMD python3 /main.py

这就是我得到的:

Sending build context to Docker daemon  11.26kB
Step 1/6 : FROM alpine:3.5
 ---> dc496f71dbb5
Step 2/6 : RUN apk add --update     python3
 ---> Running in 7f5099b20192
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.5/main: could not connect to server (check repositories file)
WARNING: Ignoring APKINDEX.c51f8f92.tar.gz: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.5/community: could not connect to server (check repositories file)
WARNING: Ignoring APKINDEX.d09172fd.tar.gz: No such file or directory
ERROR: unsatisfiable constraints:
  python3 (missing):
    required by: world[python3]
The command '/bin/sh -c apk add --update     python3' returned a non-zero code: 1

我能够从浏览器访问URL,因此服务器本身没有问题。

I was able to access the URL from a browser, so there is no problem with the server itself.

我怀疑这与代理没有传播到容器有关,正如这个问题中所述,在运行 docker run alpine env 时也没有获得http_proxy行。但是,将代理输入配置文件后,它终于出现了。但是问题仍然存在。

I suspected that it has something to do with the proxy not being propagated to the container, as explained in this question, since I also did not get the http_proxy line when running docker run alpine env. However, after entering the proxies into the config file, it finally appeared. Yet the problem still exists.

我还尝试按照此处的指示更改DNS,但是问题仍然没有解决。

I also tried to change the DNS as instructed here, but the problem is still unsolved.

推荐答案

我终于设法解决了这个问题,罪魁祸首是我在CNTLM中的设置。
有关背景故事,请检查这篇文章

I finally managed to solve this problem, and the culprit was my setting in the CNTLM. For a background story, please check this post.

此问题的根本原因是docker容器由于 CNTLM.ini 中的IP设置错误而无法从VM内部访问Internet。

The root cause of this problem is that the docker container could not access the internet from inside the VM due to wrong IP setting inside the CNTLM.ini.

通常,CNTLM默认会监听 127.0.0.1:3128 来转发代理。我遵循默认设置,因此在Docker上设置代理设置(对于守护程序-通过GUI ,对于容器-通过 config.json )也设置在该地址和端口中。事实证明,此本地主机不适用于docker所在的虚拟机,因为该虚拟机具有自己的本地主机。长话短说,解决方案是在以下所有位置将该地址更改为dockerNAT IP地址 10.0.75.1:3128 ):

Normally CNTLM listens to 127.0.0.1:3128 by default to forward the proxy. I followed the default, and thus set the proxy setting on Docker (for the daemon - through the GUI, and for the container - through config.json) is also set into that address and port. It turns out that this "localhost" does not apply to the VM where docker sits, since the VM has its own localhost. Long story short, the solution is to change that address into dockerNAT IP address (10.0.75.1:3128) in all of the following locations:


  • CNTLM.ini (在 Listen 行。实际上,如果我们也将CNTLM用于其他目的,则可能会提供多个 Listen 行)

  • Docker守护程序的代理(通过Docker设置GUI)

  • Docker容器 config.json (通常位于 C:\Users\< username> \.docker ),方法是添加以下行:

  • CNTLM.ini (on the Listen line. Actually if we use CNTLM for other purposes as well, it is possible to supply more than one Listen line)
  • Docker daemon's proxy (through the Docker setting GUI)
  • Docker container config.json (usually in C:\Users\<username>\.docker), by adding the following lines:

"proxies":
 {
   "default":
   {
     "httpProxy": "http://10.0.75.1:3128",
     "httpsProxy": "http://10.0.75.1:3128",
     "noProxy": <your no_proxy>
   }
 }


还请检查以下相关帖子:

also check these related posts:

  • Building a docker image for a node.js app fails behind proxy
  • Docker client ignores HTTP_PROXY envar and build args
  • Beginner having trouble with docker behind company proxy

这篇关于Docker构建错误:“无法连接到服务器” (在代理后面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆