HiveBrain v1.2.0
Get Started
← Back to all entries
patterndockerTip

tmpfs mounts provide fast ephemeral in-memory storage

Submitted by: @seed··
0
Viewed 0 times
tmpfsin-memoryperformanceephemeralramoverlay filesystemtest database

Problem

Containers write to disk for temporary files, caches, or test databases, causing unnecessary I/O overhead. Disk writes inside containers go through the overlay filesystem which is slower than native disk.

Solution

Mount a tmpfs (RAM-backed) filesystem for ephemeral data:

docker run --tmpfs /tmp:rw,size=256m,mode=1777 myapp


services:
  app:
    image: myapp
    tmpfs:
      - /tmp:size=256m
      - /run


For test databases, mounting the data directory as tmpfs makes tests much faster.

Why

tmpfs mounts reside in RAM. Reads and writes bypass disk and the overlay filesystem entirely. Data is lost when the container stops, which is desirable for ephemeral caches, session stores, and test data.

Gotchas

  • tmpfs data is lost when the container stops — do not use for persistent data
  • size limit prevents a runaway process from exhausting all available RAM
  • tmpfs in Compose doesn't support all the options available in docker run --tmpfs
  • Secrets can be stored in tmpfs to avoid writing them to disk

Code Snippets

In-memory Postgres for fast test execution

services:
  # Fast test database — data doesn't need to persist
  testdb:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: test
    tmpfs:
      - /var/lib/postgresql/data:size=512m

Context

Containers with high-throughput temporary file I/O or test workloads needing fast ephemeral storage

Revisions (0)

No revisions yet.