Dockerfile找不到应用程序副本

2024-05-21 04:03:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我在一个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

这些是码头工人的东西-合成.yml公司名称:

^{pr2}$

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/应用程序副本没用。另外,当我运行docker compose down,然后编辑文件时,当我再次运行docker compose up时,它似乎没有注册对文件的任何更改。我错过了什么?在


Tags: composedockerpydockerfiletxt文件夹app应用程序
2条回答

对于windows:

一个解决方案是删除“docker”中的“卷”-合成.yml“。在

问题是,它不会更新/同步主机中的文件。(这是我的情况) 我试着摆弄卷,发现卷中的”(“:/code”)不起作用。它使我在docker中的代码目录为空。在

我建议您将项目转移到C:/Users/YourUsername/(可以是一个更深的目录,只要它在路径下),然后在docker compose的volume参数中,将。/code“更改为”C:/Users/YourUsername/project_文件夹:/code“

你在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

^{pr2}$

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


在Windows上,请注意路径及其共享状态:请参见issue 3157。在

相关问题 更多 >