我有一个包,我想将它构建到一个依赖于我系统上相邻包的 docker 镜像中。
我的 requirements.txt
看起来像这样:
-e ../other_module numpy==1.0.0 flask==0.12.5
当我在 virtualenv 中调用 pip install -r requirements.txt
时,效果很好。但是,如果我在 Dockerfile 中调用它,例如:
ADD requirements.txt /app RUN pip install -r requirements.txt
并使用 docker build 运行。
我收到一条错误消息:
../other_module 应该是本地项目的路径或以 svn+、git+、hg+ 或 bzr+ 开头的 VCS url
如果有的话,我在这里做错了什么?
最佳答案
首先,您需要将 other_module
添加到您的 Docker 镜像中。没有它,pip install
命令将无法找到它。但是,根据 the documentation,您不能 ADD
Dockerfile 目录之外的目录。 :
The path must be inside the context of the build; you cannot ADD ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.
因此,您必须将 other_module
目录移动到与 Dockerfile 相同的目录中,即您的结构应该类似于
.
├── Dockerfile
├── requirements.txt
├── other_module
| ├── modue_file.xyz
| └── another_module_file.xyz
然后将以下内容添加到 dockerfile:
ADD /other_module /other_module
ADD requirements.txt /app
WORKDIR /app
RUN pip install -r requirements.txt
WORKDIR
命令将您移动到 /app
,因此下一步,RUN pip install...
将在 中执行>/app
目录。从应用程序目录中,您现在拥有目录../other_module
可用
https://stackoverflow.com/questions/44708481/