Pip安装-e软件包不会出现在Docker中 [英] Pip install -e packages don't appear in Docker
问题描述
我有一个 requirements.txt
文件,其中包括:
I have a requirements.txt
file containing, amongst others:
Flask-RQ==0.2
-e git+https://token:x-oauth-basic@github.com/user/repo.git#egg=repo
当我尝试使用Docker Compose构建一个Docker容器时,它会同时下载这两个软件包,同时安装它们,但是当我执行 pip freeze
没有 -e
包的标志。当我尝试运行应用程序时,看起来好像这个包没有被安装。以下是构建的相关输出:
When I try to build a Docker container using Docker Compose, it downloads both packages, and install them both, but when I do a pip freeze
there is no sign of the -e
package. When I try to run the app, it looks as if this package hasn't been installed. Here's the relevant output from the build:
Collecting Flask-RQ==0.2 (from -r requirements.txt (line 3))
Downloading Flask-RQ-0.2.tar.gz
Obtaining repo from git+https://token:x-oauth-basic@github.com/user/repo.git#egg=repo (from -r requirements.txt (line 4))
Cloning https://token:x-oauth-basic@github.com/user/repo.git to ./src/repo
这是我的 Dockerfile
:
FROM python:2.7
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip install -r requirements.txt
COPY . /usr/src/app
我发现这种情况非常奇怪,不胜感激。 >
I find this situation very strange and would appreciate any help.
推荐答案
我遇到了一个类似的问题,一个可能的问题可能出现的方式来自于:
I ran into a similar issue, and one possible way that the problem can appear is from:
WORKDIR /usr/src/app
在 pip install
之前设置。 pip将在WORKDIR内创建 src /
目录(安装包)。现在所有这一切都不应该是一个问题,因为您的应用程序文件复制时不应该覆盖 src /
目录。
being set before pip install
. pip will create the src/
directory (where the package is installed) inside of the WORKDIR. Now all of this shouldn't be an issue since your app files, when copied over, should not overwrite the src/
directory.
但是,您可能将装载卷到 / usr / src / app
。当您这样做时,您将覆盖 / usr / src / app / src
目录,然后找不到您的包。
However, you might be mounting a volume to /usr/src/app
. When you do that, you'll overwrite the /usr/src/app/src
directory and then your package will not be found.
所以一个修复是在 pip install
之后移动WORKDIR。因此,您的 Dockerfile
将如下所示:
So one fix is to move WORKDIR after the pip install
. So your Dockerfile
will look like:
FROM python:2.7
RUN mkdir -p /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip install -r /usr/src/app/requirements.txt
COPY . /usr/src/app
WORKDIR /usr/src/app
我。希望它会为你而生。
This fixed it for me. Hopefully it'll work for you.
这篇关于Pip安装-e软件包不会出现在Docker中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!