python - Docker 不保存图像并写入文本文件(Python 应用程序)
问题描述
我创建了一个 Python 应用程序,它从电子邮件消息中接收图像并将其存储在本地名为Images的文件夹下。它还将一些配置数据写入dict.txt。当我在没有 Docker 的情况下运行应用程序(使用 Pycharm IDE)时,这是可行的。但是,当我使用 docker 时,不会发生这种预期的行为。
目录结构(容器):
IntermediateService
├─── Dockerfile
├─── requirements.txt
└─── src
└─── emailAccountA.py
└─── emailAccountB.py
└─── main.py
└─── dict.txt
└─── Images
Dockerfile:
# set base image (host OS)
FROM python:3.8.5
# set the working directory in the container
WORKDIR /code
# copy the dependencies file to the working directory
COPY requirements.txt .
# install dependencies
RUN pip --default-timeout=100000 install -r requirements.txt
# copy the content of the local src directory to the working directory
COPY src/ .
# command to run on container start
CMD [ "python", "./main.py" ]
我运行以下 docker 命令:
docker build -t intermediateservice .
docker run intermediateservice
容器构建和运行没有任何问题,只是不写入dict.txt并将下载的图像保存到Images 文件夹(文本文件和文件夹始终为空)。需要做些什么来解决这个问题?
解决方案
正如@john-gordon 所说,它写入容器内的文件系统,容器退出时会丢失。运行时需要将文件夹挂载到容器中:
docker run -v $(pwd)/Images:/code/Images intermediateservice
推荐阅读
- asp.net - @if 在更改其他表单元素时不呈现表单选项
- java - 内部连接 hql 查询多对多不起作用
- monitoring - cAdvisor 显示的磁盘使用情况
- firebase - 将数据发送到 React Native 中的导入模块
- ruby - 下一个键/值对在尝试使用新键添加对时覆盖散列中的现有对
- java - 创建文本修改系统,如 stackoverflow 上的答案字段
- php - 通过 exec 运行命令而不将其发送到后台时,Laravel 挂起
- python - 布尔语句Python中的零除法错误
- javascript - 如何在离子或角度页面中显示自定义 javascript 小部件
- ios - Swift 共享扩展无法加载图像