如何使用pip作为docker构build的一部分来安装本地包?
我有一个包,我想build立一个docker的形象,这取决于我的系统上相邻的包。
我的requirements.txt
看起来像这样:
-e ../other_module numpy的== 1.0.0 烧瓶== 0.12.5
当我在一个virtualenv中调用pip install -r requirements.txt
,这个工作正常。 但是,如果我在一个Dockerfile中调用它,例如:
添加requirements.txt /应用程序 运行pip install -r requirements.txt
并使用docker build .
运行docker build .
我得到一个错误说:
../other_module should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+
如果有的话,我在这里做错了什么?
首先,你需要添加other_module
到你的Docker镜像。 没有这个, pip install
命令将无法find它。 但是你不能根据文档 ADD
一个Dockerfile目录之外的目录:
path必须在构build的上下文中; 你不能添加../something /东西,因为docker build的第一步是将上下文目录(和子目录)发送到docker守护进程。
所以你必须将other_module
目录移动到other_module
目录中,也就是说你的结构应该看起来像这样
. ├── 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
目录中执行。 从app-directory,你现在有../other_module
可用的目录