【发布时间】:2020-11-24 15:36:28
【问题描述】:
我创建了一个 Python 应用程序,它从电子邮件消息中接收图像并将其存储在本地名为 Images 的文件夹下。它还将一些配置数据写入 dict.txt。当我在没有 Docker 的情况下运行应用程序(使用 Pycharm IDE)时,这是可行的。但是,当我使用 docker 时,不会发生这种预期的行为。
ImageLink: Directory structure (Pycharm IDE)
目录结构(容器):
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 文件夹(文本文件和文件夹总是空的)。需要做什么来解决这个问题?
【问题讨论】:
-
它写入文件系统inside容器,当容器退出时丢失。
-
@JohnGordon 谢谢。 dockerfile或者docker命令需要做哪些修改?
标签: python docker docker-compose dockerfile devops