Docker 构建:连接到 Wi-Fi 扩展器(tp-link)时 Python 包安装失败

Docker 构建:连接到 Wi-Fi 扩展器(tp-link)时 Python 包安装失败

我正在尝试为我的 Python Web 服务器构建 Docker 镜像,但一直收到错误消息No matching distribution found for <package-name>。在我的情况下,我尝试安装的软件包是 alembic 1.11.1,但正如您将在下面看到的,这与特定软件包无关。

仅当我连接到 tp-link wi-fi 扩展器时才会发生此错误。

详细来说,错误如下:

$ docker build -t test

[+] Building 56.3s (9/10)                                                                                                                                                           
 => [internal] load build definition from Dockerfile                                                                                                                           0.0s
 => => transferring dockerfile: 354B                                                                                                                                           0.0s
 => [internal] load .dockerignore                                                                                                                                              0.0s
 => => transferring context: 2B                                                                                                                                                0.0s
 => [internal] load metadata for docker.io/library/python:3.10-alpine                                                                                                          1.6s
 => CACHED [1/6] FROM docker.io/library/python:3.10-alpine@sha256:a578a0d69e5df6a9d7af73699553dc80717b2871a24cc9536130a40512b41295                                             3.1s
 => [internal] load build context                                                                                                                                              7.5s
 => => transferring context: 3.59kB                                                                                                                                            0.0s
 => [2/6] WORKDIR /code                                                                                                                                                        4.5s
 => [3/6] COPY ./requirements.txt /code/requirements.txt                                                                                                                       0.0s
 => [4/6] COPY ./alembic.ini /code/alembic.ini                                                                                                                                 0.1s
 => ERROR [5/6] RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt                                                                                            46.9s
------                                                                                                                                                                              
 > [5/6] RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt:                                                                                                        
#0 9.171 WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f9a8b718640>: Failed to establish a new connection: [Errno -3] Try again')': /simple/alembic/                                                             
#0 14.68 WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f9a8b718af0>: Failed to establish a new connection: [Errno -3] Try again')': /simple/alembic/                                                             
#0 20.68 WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f9a8b718f70>: Failed to establish a new connection: [Errno -3] Try again')': /simple/alembic/
#0 27.69 WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f9a8b719120>: Failed to establish a new connection: [Errno -3] Try again')': /simple/alembic/
#0 36.70 WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f9a8b7193f0>: Failed to establish a new connection: [Errno -3] Try again')': /simple/alembic/
#0 41.71 ERROR: Could not find a version that satisfies the requirement alembic==1.11.1 (from versions: none)
#0 41.71 ERROR: No matching distribution found for alembic==1.11.1
------
Dockerfile:8
--------------------
   6 |     COPY ./alembic.ini /code/alembic.ini
   7 |     
   8 | >>> RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
   9 |     
  10 |     COPY ./app /code/app
--------------------
ERROR: failed to solve: process "/bin/sh -c pip install --no-cache-dir --upgrade -r /code/requirements.txt" did not complete successfully: exit code: 1

另一方面,当我直接连接到路由器时,运行相同的命令(即docker build -t test)可以毫无问题地构建图像。

如果这不是网络问题,我尝试了以下操作(连接到 wifi 扩展器时):

我将平台指定为x86_64正如其他帖子所建议的那样,但这并没有解决问题。此外,我也尝试过更改基础图像到各种其他版本,例如python:3.10-bullseyepython:3.10-bookwormpython:3.10-slim

我也尝试删除特定的 alembic 版本,但问题仍然存在。然后我尝试删除整个 alembic 要求,但下一个包会出现同样的错误,这意味着这是一个与包无关的错误,无法安装我的项目的任何依赖项。

Dockerfile 正在使用这个:

FROM --platform=x86_64 python:3.10-alpine 
WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
COPY ./alembic.ini /code/alembic.ini
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY ./app /code/app 
EXPOSE 80
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]

requirements.txt文件是这样的(我再说一遍,这里的包对于发生的错误不起任何作用):

alembic==1.11.1
anyio==3.6.2
bcrypt==4.0.1
certifi==2023.5.7
click==8.1.3
colorama==0.4.6
dnspython==2.3.0
ecdsa==0.18.0

操作系统和工具版本:

  • Ubuntu 22.04.2 LTS x86_64
  • Docker 版本 24.0.2,内部版本 cb74dfc
  • Wi-Fi 扩展器设备:TL-WA860RE

答案1

我可能太晚才注意到这个问题,而您只是继续往下看。但我猜您的 Wi-Fi 扩展器要么配置错误,要么故意更改 HTTPS 证书(又称创建中间人漏洞),而 pip 正在做正确的事情,不允许恶意证书。

Pip 默认使用系统包含的 ca 证书。Alpine Linux 的官方图像使用 alpine 的 ca 证书。

我的猜测是,如果您在 Wi-fi 扩展器上使用 VPN,那么您就可以顺利进行构建。Sshuttle 可以轻松地在您可以访问的服务器上创建 VPN,如果您想测试一下。

相关内容