Speed Up Containers with tmpfs mounts
When working with Docker, you often need temporary storage for caching, session data, or other ephemeral files. Typically, we reach for…
Speed Up Containers with tmpfs mounts
When working with Docker, you often need temporary storage for caching, session data, or other ephemeral files. Typically, we reach for volumes or bind mounts, but there’s a lesser-known, high-performance option: tmpfs mounts. Unlike regular storage methods, tmpfs mounts store data directly in RAM, making them extremely fast while ensuring that nothing is written to disk. Let’s dive into why this can be a game-changer for your containers!

What is a tmpfs Mount?
A tmpfs mount is a memory-backed filesystem that exists only while the container is running. When the container stops, the data disappears. This is particularly useful when:
✅ You need fast read/write access (RAM is much faster than disk). ✅ You don’t want data to persist beyond the container’s lifecycle. ✅ You want to reduce disk I/O load for performance optimization. ✅ You need a secure, ephemeral storage for temporary secrets.
How to Use tmpfs Mounts in Docker
1. The Quick Way: --tmpfs Flag
docker run --tmpfs /mytmp:size=64m
Creates a 64MB tmpfs mount at /mytmp
2. The More Flexible Way: --mount Flag
docker run --mount type=tmpfs,destination=/mytmp,tmpfs-size=128m,tmpfs-mode=1700 alpine
Why prefer --mount? It’s more explicit, production-friendly, and supports additional options. You can also set it to read-only for security (mode=1700).
⚠️ Hidden Risk: tmpfs May Not Always Stay in RAM!
tmpfsmounts in Docker map directly totmpfsin the Linux kernel. As such, the temporary data may be written to a swap file and thereby persisted to the filesystem. So you may need to disable swap first
Limitations of tmpfs Mounts
- Not Shareable — Unlike volumes and bind mounts,
tmpfsmounts cannot be shared between multiple containers. - Linux-Only — This feature is exclusive to Docker on Linux and isn’t available on other operating systems.
- Permission Resets — File permissions on
tmpfsmay reset after a container restarts. Usinguid/gidsettings can sometimes help as a workaround.
Kubernetes In-Memory Storage: How emptyDir Compares to tmpfs
In Kubernetes, the **emptyDir volume** behaves similarly to Docker’s tmpfs when configured with medium: "Memory"
apiVersion: v1
kind: Pod
metadata:
name: memory-pod
spec:
containers:
- name: app-container
image: alpine
volumeMounts:
- mountPath: "/mytmp"
name: temp-storage
volumes:
- name: temp-storage
emptyDir:
medium: "Memory" # Use RAM instead of disk
sizeLimit: 512Mi # Optional: Limit memory usage
Above pod mounts /mytmp as RAM-based storage, auto-clears on Pod termination, and leverages Kubernetes-native storage.
Advantages of emptyDir (Memory) Over tmpfs
- Shared Storage: emptyDir can be accessed by multiple containers in a Pod, whereas tmpfs is limited to a single container.
- Pod-Level Persistence: Data in emptyDir persists as long as the Pod is running, while tmpfs data is lost when the container stops.
- Kubernetes Native: emptyDir is managed by Kubernetes, eliminating the need for manual mounts like tmpfs in Docker.
- Cross-Platform Compatibility: Unlike tmpfs, which works only on Linux, emptyDir works across different Kubernetes environments.
Both tmpfs in Docker and emptyDir with Memory in Kubernetes provide high-speed, in-memory storage for ephemeral data. If you’re running standalone containers, tmpfs can significantly improve performance by reducing disk I/O. However, for Kubernetes workloads, emptyDir offers more flexibility by allowing multiple containers in a Pod to share memory-backed storage while benefiting from Kubernetes-native management.
I hope this deep dive into in-memory storage for Docker and Kubernetes has provided valuable insights.
Thanks for reading! 😊 Boost your containerized applications with the right in-memory storage solution and unlock better performance today!
메타데이터
- post_id
- bc5faadee9e0
- slug
- speed-up-containers-with-tmpfs-mounts-bc5faadee9e0
- url
- https://medium.com/@hemantbhosale/speed-up-containers-with-tmpfs-mounts-bc5faadee9e0
- canonical_url
- https://medium.com/@hemantbhosale/speed-up-containers-with-tmpfs-mounts-bc5faadee9e0
- author_url
- https://medium.com/@hemantbhosale
- status
- ok
- fetched_at
- 2026-06-26 06:47:43