我正在尝试设置运行 python 2.7 的 Docker 镜像。我想要在容器中运行的代码依赖于我在构建 Docker 镜像期间尝试使用 pip 获取的包。我的问题是 pip 仅获取包的某些部分,而尝试获取其他包时发出错误。这是我的 Docker 文件:
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "./my_script.py"]
这里是requiremnts.txt
Flask
redis
time
sys
opcua
Pip 在收集 Flask 和 redis 时没有问题,但在收集 time 时出现错误(与 redis 相同的问题>sys 和 opcua)
我应该怎样做才能使其适用于所有 pip 软件包?提前致谢!
最佳答案
这里的问题是时间是 Python's standard library 的一部分,因此它与 Python 的其余部分一起安装。这意味着您不能(并且不能)pip 安装它。这适用于 sys以及。从您的 requirements.txt
中取出这些内容,您就可以开始了!
关于python - 在 python Docker 容器中安装 pip 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51287636/