【发布时间】:2022-01-17 22:09:32
【问题描述】:
设置
- 项目
- 源
- main.py
- Dockerfile
- 源
Dockerfile(原始,需要修改)
FROM python:3
ADD src/main.py /
RUN chmod +x main.py
RUN /usr/local/bin/python -m pip install --upgrade pip
COPY . /opt/app
RUN pip install -r /opt/app/requirements.txt
ADD / /usr/local
ENTRYPOINT [ "python", "./main.py" ]
main.py
>if __name__ == '__main__':
if len(sys.argv) == 2:
main(sys.argv[1])
def main(logs_file_archive):
unzip_logs(logs_file_archive) # unzips all logs from the provided path to the folder with the same name as archive/Extracted directory
create_csv_files() # creates CSV files needed to plot graph
process_files() # populate CSV files generated with the right data
plot(logs_file_archive) # build this data representation
实际/期望的行为
实际:
2022-01-17T22:05:31.547047838Z File "//./main.py", line 214, in <module>
2022-01-17T22:05:31.547210046Z main(sys.argv[1])
2022-01-17T22:05:31.547259438Z File "//./main.py", line 187, in main
2022-01-17T22:05:31.547670294Z unzip_logs(logs_file_archive)
2022-01-17T22:05:31.547732344Z File "//./main.py", line 54, in unzip_logs
2022-01-17T22:05:31.548296998Z with zipfile.ZipFile(file_path, "r") as zip_ref:
2022-01-17T22:05:31.548350898Z File "/usr/local/lib/python3.10/zipfile.py", line 1240, in __init__
2022-01-17T22:05:31.549638566Z self.fp = io.open(file, filemode)
2022-01-17T22:05:31.549692977Z FileNotFoundError: [Errno 2] No such file or directory: '/Users/user/PerfReader/misc/archive.zip'
No such file or directory: '/Users/user/PerfReader/misc/archive.zip' 应该很好...因为 Docker 机器中没有这样的文件。
期望:容器使用Dockerfile运行,数据处理,绘图实时显示或保存为文件并传输到主机
问题/问题描述
- 我不完全确定如何将指定的文件传输到 Docker 容器。我阅读了https://docs.docker.com/storage/volumes/,但它没有提供任何示例,因此我寻求有关如何安装卷的示例。
- 如果我在 main.py 中的 plot() 可以正确绘制数据,我在显示这些数据时有哪些选择(整个练习的输出是绘图)?我可以从 Docker 实时显示绘图吗?还是我唯一的选择是生成一个绘图,然后使用
matplotlib.pyplot.savefig将其传输回主机?
【问题讨论】:
-
您的应用程序似乎在读取主机数据,并且要么写入主机数据,要么需要主机显示。 Docker(按设计)使访问所有这些“主机”事物变得困难。 Python 虚拟环境会更好地满足您的需求吗?
标签: python docker docker-volume file-copying