如何在Docker中管理临时文件? [英] How to manage temporary files in docker?

查看:80
本文介绍了如何在Docker中管理临时文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个Java应用程序,该应用程序以给定格式读取一些数据,并在temp目录中写入CSV文件.完全写入此文件后,数据将批量加载到数据库中.加载完成后,将立即删除文件.此文件不应共享.

I'm running a Java application that reads some data in a given format and writes a CSV file in the temp directory. After this file is fully written, the data is bulk loaded in the database. When the load is done, the file is immediately deleted. This file should not be shared.

现在,我想在docker容器中运行此应用程序的jar.

Now, I want to run a jar of this application in a docker container.

从文档中,我读到:

写入容器的可写层需要存储驱动程序来管理文件系统.存储驱动程序使用Linux内核提供联合文件系统.与使用直接写入主机文件系统的数据卷相比,这种额外的抽象降低了性能.

Writing into a container’s writable layer requires a storage driver to manage the filesystem. The storage driver provides a union filesystem, using the Linux kernel. This extra abstraction reduces performance as compared to using data volumes, which write directly to the host filesystem.

据我了解,如果我创建一个用于映射主机/tmp文件夹的卷会更好,这样我可以为I/O操作获得更好的性能.另一方面,尽管我的用例由临时文件组成,但似乎出于持久性原因而使用了卷.

From what I understand, it would be better if I create a volume to map the host /tmp folder so I can have better performance for I/O operations. On the other hand, it seems that volumes are used for persistence reasons, although my use case consists of temporary files.

管理临时文件时是否建议使用卷?如果没有,是否有一种有效的方法来处理Docker中的临时文件?

Are volumes recomended when managing temporary files? If not, is there a efficient approach to deal with temporary files in docker?

推荐答案

如果需要性能而不是持久性,则可以创建tmpfs卷.例如

You can create a tmpfs volume if you want performance and not persistence. E.g.

docker run --tmpfs /tmp -d java-img

请注意,即使在容器重新启动之间也没有持久性.同样,这将从一个空目录开始,而不是从该安装点的映像目录初始化.

Note that there is no persistence, even between container restarts. Also this will start with an empty directory rather than initializing from the image directory at that mount point.

有关更多详细信息,包括挂载tmpfs卷的其他方法,请参见: https://docs.docker.com/storage/tmpfs/

For more details, including other ways to mount a tmpfs volume, see: https://docs.docker.com/storage/tmpfs/

这篇关于如何在Docker中管理临时文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆