首页 > 解决方案 > DockerInDocker:在 docker 镜像构建时 pip install 失败

问题描述

我正在开发一个安装了 Istio 的 Kubernetes 集群,并且我正在使用docker:dindpod 上的映像来动态构建 docker 映像。问题是,一旦构建阶段到达RUN pip install numpy我的 Dockerfile ,它就会失败并抛出以下错误:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/numpy/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/numpy/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/numpy/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/numpy/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/numpy/
ERROR: Could not find a version that satisfies the requirement numpy (from versions: none)
ERROR: No matching distribution found for numpy

用于测试的 Dockerfile:

FROM python:3.7.7-slim-buster

RUN pip install numpy

CMD ["echo", "Testing..."]

包含docker:dind图像的 pod 能够安装 Python 包,执行:

/ # apk add python3 py3-pip
/ # pip install numpy
Collecting numpy
  Downloading numpy-1.19.0.zip (7.3 MB)
     |████████████████████████████████| 7.3 MB 1.4 MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  ...

有效(实际上由于构建依赖关系而失败,但它可以连接到 pypi),但执行以下操作:

/ # cd tmp/
/ # vi Dockerfile # Set the content as described above
/ # docker build .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM python:3.7.7-slim-buster
3.7.7-slim-buster: Pulling from library/python
8559a31e96f4: Pull complete 
62e60f3ef11e: Pull complete 
286adfd1ee25: Pull complete 
8973789a3a6b: Pull complete 
9b8d369425a7: Pull complete 
Digest: sha256:5b25848c082804c500e8cadce6d1b344791aa39d82cb9d56285c65e3e937f0c2
Status: Downloaded newer image for python:3.7.7-slim-buster
 ---> 4cbd5021babc
Step 2/3 : RUN pip install numpy
 ---> Running in 0496b1cfcbb0
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/numpy/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/numpy/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/numpy/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/numpy/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /simple/numpy/
ERROR: Could not find a version that satisfies the requirement numpy (from versions: none)
ERROR: No matching distribution found for numpy

简直失败了……

我想知道是否有人遇到过这样的事情并能够解决它。

提前致谢。:)

标签: kubernetespipistiodocker-in-docker

解决方案


推荐阅读