简体   繁体   English

在python Docker容器中安装pip包

[英]Installing pip packages in python Docker container

I'm trying to setup a Docker image running python 2.7. 我正在尝试设置运行python 2.7的Docker镜像。 The code I want to run within the container relies on packages I'm trying to get using pip during the Docker image built. 我想在容器中运行的代码依赖于我在构建Docker镜像期间尝试使用pip的包。 My problem is that pip only gets some part of the packages issuing an error while trying to get the others. 我的问题是pip只会在尝试获取其他包时发现错误的一部分包。 Here is my Docker file: 这是我的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"]

An here the requiremnts.txt 这里是requiremnts.txt

Flask
redis
time
sys
opcua

Pip has no problem with collecting Flask and redis , but issues error when it comes to collect time (the same problem with sys and opcua ) Pip收集Flaskredis没有问题,但是在收集时间方面会出错( sysopcua也有同样的问题)

构建过程中的Docker-machine输出

what should I do to make it work with all pip packages? 我该怎么做才能使它适用于所有pip包? Thanks in advance! 提前致谢!

The issue here is time is a part of Python's standard library , so it's installed with the rest of Python. 这里的问题是时间是Python标准库的一部分,所以它与Python的其余部分一起安装。 This means you do not (and cannot ) pip install it. 这意味着你没有( 也不能 )pip安装它。 This goes for sys as well. 这也适用于sys Take these out of your requirements.txt and you should be good to go! 从你的requirements.txt取出这些,你应该好好去!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM