8.4 Tmpfs Mounts
A focused guide to Tmpfs Mounts, connecting core concepts with practical Docker and container operations.
Tmpfs mounts provide a container with a mount point backed entirely by host memory rather than persistent disk storage, with the mounted content existing only for the container's running lifetime and disappearing completely the moment the container stops.
Creating a Tmpfs Mount
A tmpfs mount is specified through its own dedicated flag, distinct from the -v flag used for volumes and bind mounts.
docker run -d --tmpfs /app/cache myapp:1.0
This provides /app/cache as a memory-backed filesystem, with whatever the application writes there existing only in memory, never touching the host's persistent disk at all.
Specifying Size and Other Options
A tmpfs mount can be configured with specific size limits and other mount options.
docker run -d --tmpfs /app/cache:size=100m,mode=1770 myapp:1.0
Why Tmpfs Provides Fast, Ephemeral Storage
Because tmpfs content lives entirely in memory, read and write operations against it are extremely fast compared to disk-backed storage, making it well suited for temporary data that benefits from this speed and doesn't need to survive the container's life at all.
docker run -d --tmpfs /tmp myapp:1.0
Using tmpfs for a /tmp directory provides fast scratch space for an application's temporary processing needs, without that temporary data ever needing to persist.
Why Tmpfs Content Disappears Completely on Container Stop
Because tmpfs is backed by memory rather than disk, stopping the container (which releases its allocated memory) also completely and immediately discards anything stored in the tmpfs mount, with no possibility of recovery.
docker run --tmpfs /data myapp:1.0
docker stop $(docker ps -lq)
Any data written to /data during this container's run is now completely gone, having existed only in memory that has since been released.
Why Tmpfs Mounts Matter
Tmpfs mounts provide a fast, genuinely ephemeral storage option well suited to temporary, performance-sensitive data that has no need to persist beyond the container's own running life, complementing volumes and bind mounts as a third distinct storage option for a specific kind of need.