我在嵌入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时,似乎没有在文件上进行任何更改.我想念什么?
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.