python-Dockerfile找不到app.py

我在嵌入docker映像的flask应用程序中具有以下文件夹结构.

├── 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

这些是docker-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"]

当我运行docker-compose up时,出现错误

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

仅仅是因为它在子文件夹中.将参数更改为app / app.py并没有帮助.另外,当我向下运行docker-compose,然后编辑文件时,当我再次运行docker-compose时,似乎没有在文件上进行任何更改.我想念什么?

最佳答案
您在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.

原因:

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 07001 to reduce duplication between both files.

在Windows上,请注意您的路径及其共享状态:请参阅issue 3157.

相关文章

Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Li...
1、什么是docker?答:docker是开源的应用容器引擎;开发人员把他们的应用及依赖包打包发布到容器当中。...
1、什么是namespace? 答:名称空间,作用隔离容器 2、namespace隔离有那些? 答:ipc:共享内存、消息队...
1、Docker能在非Linux平台(Windows+MacOS)上运行吗? 答:可以 2 、如何将一台宿主机的docker环境...
环境要求: IP hostname 192.168.1.1 node1 项目规划: 容器网段:172.16.10.0/24 NGINX:172.16.10.10...
文档上传地址:https://files.cnblogs.com/files/lin-strive/07-docker%E8%B7%A8%E4%B8%BB%E6%9C%BA%E7...