2017-06-22 47 views
0

我已經有了一個我想要構建到Docker鏡像中的包,該鏡像取決於系統上的相鄰包。如何使用pip作爲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 should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+

什麼,如果有的話,我是不是做錯了什麼?

+0

你有Docker鏡像中的'other_module'嗎? – 9000

+0

哈德你還在Docker鏡像中加入了../ other_module? – Cleared

+0

@ 9000 @Cleared我試着用'COPY ../other_module/app'這樣的東西來複制它,但是會產生一個不同的錯誤:'構建上下文之外的禁止路徑' – AnjoMan

回答

6

首先,您需要將other_module添加到您的Docker鏡像。否則,pip install命令將無法找到它。但是你不能ADD根據the documentation的目錄中的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可用

相關問題