我在一个 Flask 应用程序中有以下文件夹结构,我将它嵌入到 docker 图像中。
├── 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 down,然后编辑文件时,当我再次运行 docker-compose up 时,它似乎没有注册对文件的任何更改。我错过了什么?
最佳答案
你在 issue 1616 中也有同样的问题
ADD . /code
WORKDIR /code
volumes:
- .:/code
原因:
在 Windows 上,请注意您的路径及其共享状态:请参阅 issue 3157 。
关于python - Dockerfile 找不到 app.py,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41529489/