2017-01-08 25 views
2

私は、ドッカー画像に埋め込んでいるフラスコアプリに、次のフォルダ構造を持っています。Dockerfileはapp.pyを見つけることができません

├── Dockerfile 
├── README.md 
├── app 
│   ├── __init__.py 
│   ├── app.py 
│   ├── db 
│   ├── imgcomp 
│   │   └── __init__.py 
│   ├── static 
│   └── templates 
│    ├── comparison_result.html 
│    ├── display_images.html 
│    ├── index.html 
│    └── upload.html 
├── docker-compose.yml 
├── requirements.txt 
└── tests 

これらは、ドッキングウィンドウ-compose.ymlの内容は以下のとおりです。

version: '2' 
services: 
    web: 
    build: . 
    ports: 
     - "5000:5000" 
    volumes: 
     - .:/code 

これらはDockerfileの内容は以下のとおりです。

FROM python:3.4-alpine 
ADD . /code 
WORKDIR /code 
RUN pip install -r requirements.txt 
CMD ["python", "app.py"] 

私がドッキングウィンドウ-構成を実行すると、私が手エラー:

web_1 | python: can't open file 'app.py': [Errno 2] No such file or directory 

Simpそれはサブフォルダ内にあるからです。 app/app.pyへの引数の変更は役に立ちません。また、ドッカーを作成してコンパイルを実行した後、ファイルを編集すると、ドッカーを作成し直したときにファイルに変更が登録されていないように見えます。私は何が欠けていますか?

When running an app on a remote host, you'll need to remove any volumes entries that mount anything in from a local directory.

The reason we promote both adding your code to the image and mounting it as a volume is so that doing a docker-compose build gets you an image that's ready to deploy to a remote server, but whose code can still be mounted when developing locally so it can be live-reloaded.

If you want to use Compose to both develop an app locally and deploy it to the cloud, the best practice is to have a file for each - docker-compose.yml for local development and something else (e.g. remote.yml) for remote deployment - and use the -f flag to pass the alternate file in when deploying.

You can use the extends option to reduce duplication between both files.


+0

「フラスコ」コマンドを使用してFlaskアプリを実行する予定はありませんか? 「フラスコ走行」? –

+0

パッケージの場合のみ。また、start.pyスクリプトとしてapp.pyを使用してnodejsのように起動することもできます。 – sakurashinken

答えて

0

あなたが issue 1616

the issue appears to primarily be a consequence of the ADD/WORKDIR in the Dockerfile:

ADD . /code 
WORKDIR /code 

Conflicting with the volume mapping in the docker-compose.yml

volumes: 
- .:/code 

I may have misread the instructions but had both.

理由で同じ問題を抱えています

Windowsでは、パスとその共有状態に注意してください:issue 3157を参照してください。

+0

onguild pythonイメージを使用すると、あなたのためにCOPYを行うことに注意してください:https://github.com/docker-library/python/issues/150#issuecomment-255869639 – VonC

関連する問題