2017-06-22 9 views
0

システム上の隣接するパッケージに依存するドッカーイメージに組み込みたいパッケージがあります。dockerビルドの一部としてpipを使ってローカルパッケージをインストールするには?

 
-e ../other_module 
numpy==1.0.0 
flask==0.12.5 

私はvirtualenvの中pip install -r requirements.txtを呼び出すと、これは正常に動作します:

requirements.txtは次のようになります。私はDockerfileでこれを呼び出す場合は、例えば:

../other_module should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+

は、どちらかといえば、私はここで間違って何をやっている:

 
ADD requirements.txt /app 
RUN pip install -r requirements.txt 

と実行が、私は次というエラーを取得しdocker build .を使用して?

+0

Dockerイメージに 'other_module'がありますか? – 9000

+0

あなたは '../ other_module'をドッカーの画像にも追加しましたか? – Cleared

+0

@ 9000 @Cleared私は 'COPY ../other_module/app'のようなものを使ってコピーしようとしましたが、' Build contextの外に禁止されたパス 'という別のエラーを表示します。 – AnjoMan

答えて

6

まず、other_moduleをDockerイメージに追加する必要があります。それがなければ、pip installコマンドはそれを見つけることができません。しかし、あなたがADDthe 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.

あなたの構造が

のようになります。すなわちあなたは、あなたのDockerfileと同じディレクトリに 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が利用可能になりました。

関連する問題