python-Dockerfile找不到app.py
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python-Dockerfile找不到app.py,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2074字,纯文字阅读大概需要3分钟。
内容图文
![python-Dockerfile找不到app.py](/upload/InfoBanner/zyjiaocheng/667/ae9d3b8c56a94402bec06d295094aa62.jpg)
我在嵌入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.
内容总结
以上是互联网集市为您收集整理的python-Dockerfile找不到app.py全部内容,希望文章能够帮你解决python-Dockerfile找不到app.py所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。