加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

python-Dockerfile找不到app.py

发布时间:2020-12-16 03:25:18 所属栏目:安全 来源:网络整理
导读:我在嵌入docker映像的flask应用程序中具有以下文件夹结构. ├── Dockerfile├── README.md├── app│?? ├── __init__.py│?? ├── app.py│?? ├── db│?? ├── imgcomp│?? │?? └── __init__.py│?? ├── static│?? └── templates

我在嵌入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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读