构建docker映像时无法安装要求

问题描述 投票:1回答:1

[尝试在Docker中构建一个简单的Django应用,并且它在Fedora 31上有效,但在Fedora 32上无效。

这是我的Dockerfile,非常简单:

FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY manage.py manage.py
# More COPYs

CMD [ "python" "./manage.py" "runserver" ]

但是在运行pip安装时失败:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) 
after connection broken by 
'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f6bbfda0280>: 
Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/asgiref/

我试图像这样向码头工人添加--dns参数:

--dns 10.252.252.252 --dns 10.253.253.253 --dns 8.8.8.8

但是那不起作用。有什么想法吗?

python docker fedora
1个回答
2
投票

该错误表明存在网络(代理)问题,而不是Fedora问题。

[piphttps://files.pythonhosted.org中提取。

  • 您可以从主机ping通此URL吗?
  • 从主机上的Docker容器中来吗?

我发现在尝试识别问题时有问题,手动运行Dockerfile命令很有用:

docker run --interactive --tty python:3 bash

然后:

PYPI="$(\
  curl \
  --silent \
  --write-out '%{http_code}\n' \
  --output /dev/null \
  https://files.pythonhosted.org)"
if [ "200" == "${PYPI}" ]
then
  echo "accessible"
else
  echo "inaccessible"
fi

如果要一个命令:

docker run \
--interactive \
--tty \
python:3 \
  curl \
  --silent \
  --write-out '%{http_code}\n' \
  --output /dev/null \
  https://files.pythonhosted.org

这应确认PyPi是否可访问。然后,在容器内(参见上文),您可以使用类似以下内容的内容来获取有关pip install的更多信息:

pip3 --verbose install flask

NOTE用您的一个包装替换flask

© www.soinside.com 2019 - 2024. All rights reserved.