Volumes
and
bind mounts
let you share files between the host machine and container so that you can persist data even after the container is stopped.
If you’re running Docker on Linux, you have a third option: tmpfs
mounts. When you create a container with a tmpfs
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, the tmpfs
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.