问题描述
FROM python:3.8
RUN pip install --upgrade pip
EXPOSE 8000
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
# Install pip requirements
copY requirements.txt .
RUN python -m pip install -r requirements.txt
workdir /app
copY . /app
RUN useradd appuser && chown -R appuser /app
USER appuser
CMD ["gunicorn","--bind","0.0.0.0:8000","app:app"]
我想使用这个定义文件在 docker 容器中运行我的 Flask 应用程序。我可以在本地启动一个新的虚拟环境,通过 pip install -r requirements.txt
在 python 3.8 上安装所有内容,并且不会失败。
在构建 docker 镜像时,它无法安装来自 requirements.txt 的所有包。例如 this 包失败:
ERROR: Could not find a version that satisfies the requirement cvxopt==1.2.5.post1
ERROR: No matching distribution found for cvxopt==1.2.5.post1
当我注释掉 requirements.txt 中的包时,一切似乎都有效。该包本身声称与 python > 2.7 兼容。包 pywin32==228 here 的行为相同。
解决方法
您应该将版本替换为 1.2.5 (pip install cvxopt==1.2.5
)
最新版本 cvxopt 1.2.5.post1
并非与所有架构兼容:https://pypi.org/project/cvxopt/1.2.5.post1/#files
前一个兼容更多硬件,应该能够在您的 Docker 映像上运行:https://pypi.org/project/cvxopt/1.2.5/#files
,查看 wheel files in the package,cvxopt.1.2.5.post1 仅包含 Windows 版本。对于 Linux(如 docker 容器),应该使用 cvxopt.1.2.5。