tem:temporary 暂时的
背景:只有在 linux 有该种方式
If you're running Docker on Linux, you have a third option:
tmpfs
mounts. When you create a container with atmpfs
mount, the container can create files outside the container's writable layer.As opposed to volumes and bind mounts, a
tmpfs
mount is temporary, and only persisted in the host memory. When the container stops, thetmpfs
mount is removed, and files written there won't be persisted.This is useful to temporarily store sensitive files that you don't want to persist in either the host or the container writable layer.
- Unlike volumes and bind mounts, you can't share
tmpfs
mounts between containers.- This functionality is only available if you're running Docker on Linux.
在 Docker 中,每个容器都有一个可写层,这是容器在其基础镜像之上创建的。当容器运行并生成数据或更改状态时,这些更改都会写入到这个可写层中。这个可写层是容器的一部分,当容器被删除时,这个层中的所有数据也会被删除。
无论是容器被删除还是容器停止,
tmpfs
mount 中的数据都会被清除。tmpfs
是一种临时文件系统,它存储在内存中,不会持久化到磁盘。因此,当容器停止或者被删除时,tmpfs
mount 中的所有数据都会丢失。这是因为tmpfs
mount 的生命周期与容器的生命周期是绑定的
To use a tmpfs mount in a container, use the --tmpfs flag, or use the --mount flag with type=tmpfs and destination options. There is no source for tmpfs mounts. The following example creates a tmpfs mount at /app in a Nginx container. The first example uses the --mount flag and the second uses the --tmpfs flag.
解释 There is no source for tmpfs mounts