gpt4 book ai didi

Docker 构建错误 : "could not connect to server" (behind proxy)

转载 作者:行者123 更新时间:2023-12-05 00:46:49 25 4
gpt4 key购买 nike

上下文:
操作系统:Windows 10 专业版; Docker 版本:18.09.0(构建 4d60db4);企业代理背后,使用CNTLM解决this issue . (目前正在拉/运行图像工作正常)

问题:
我试图构建以下 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,因此服务器本身没有问题。

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

我也尝试按照说明更改 DNS here ,但问题仍未解决。

最佳答案

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

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

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

  • CNTLM.ini (在 Listen 线上。实际上,如果我们也将 CNTLM 用于其他目的,则可以提供多个 Listen 线)
  • Docker 守护进程的代理(通过 Docker 设置 GUI)
  • Docker 容器 config.json (通常在 C:\Users\<username>\.docker 中),添加以下几行:
    "proxies":
    {
    "default":
    {
    "httpProxy": "http://10.0.75.1:3128",
    "httpsProxy": "http://10.0.75.1:3128",
    "noProxy": <your no_proxy>
    }
    }

  • 还检查这些相关的帖子:
  • 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 构建错误 : "could not connect to server" (behind proxy),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53510864/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com