What is a tmpfs mount in Docker and when would you use it?
A tmpfs mount stores data in the host's memory only, never on disk, and it vanishes when the container stops. It suits temporary or sensitive scratch data and fast temporary files.
Explain it simply
A tmpfs mount is a whiteboard in the exam hall: fast to write on, never saved, wiped when the session ends.
The data lives in RAM (or swap), so reads and writes are quick and nothing is left on the disk afterwards. Use it for caches, session scratch files, or decrypted secrets you do not want written to storage. Because it is memory, a large tmpfs eats into available RAM, so set a size limit. It works only on Linux hosts and cannot be shared between containers.
It is often paired with a read-only root filesystem: the container cannot write anywhere except the tmpfs path, such as /tmp, which reduces what an attacker can change.
Example
docker run -d --tmpfs /tmp:rw,size=64m nginx
# or with --mount
docker run -d --mount type=tmpfs,destination=/cache,tmpfs-size=67108864 nginx
docker run -d --read-only --tmpfs /tmp nginxWhat to say in the interview
"tmpfs mounts keep data in memory only and discard it when the container stops. I use them for temporary or sensitive scratch data, set a size limit, and often combine them with --read-only."
Common mistakes
- Using tmpfs for data that must survive a restart.