我正在尝试为我的python应用程序构建一个docker容器,该容器允许在该应用程序的工作目录中对配置文件进行编辑,因此我不需要每次更改后都重新构建映像。
Dockerfile:
FROM python:3
VOLUME /app
COPY . /app
WORKDIR /app
RUN pip install requirements.txt
CMD ["python", "main.py"]
建立映像后,我将使用
部署容器docker run -d --name app -v /path/on/host/app:/app app:latest
我在容器中收到一个错误,python: can't open file 'main.py': [Errno 2] No such file or directory
和/path/on/host/app
保持为空。
我无法弄清楚我需要在Dockerfile中进行什么工作。
由于我只需要访问配置文件,因此,为了使此功能生效,我做了一些更改
Dockerfile:
FROM python:3
COPY . /app
WORKDIR /app
RUN pip install requirements.txt
VOlUME /app/config
CMD ["python","main.py"]
现在,当我运行容器时,我将配置复制到/path/on/host/app
docker run -d --name app --mount type=bind,source=/path/on/host/app,target=/app/config
这解决了我的问题,现在我可以更新配置并重新启动容器以应用更改。