✦ For everyone, free.

Practical knowledge for real and everyday life

Home

6.3.4.4 Container Shared Memory

A focused guide to Container Shared Memory, connecting core concepts with practical Docker and container operations.

Container shared memory is the size of the /dev/shm filesystem available inside a container, used by some applications for inter-process communication or as a fast, memory-backed temporary storage area, defaulting to a relatively small size that some applications may need explicitly increased.

The Default Shared Memory Size

Without explicit configuration, a container's /dev/shm defaults to a modest size, which is sufficient for many applications but can be a limiting factor for others that rely more heavily on shared memory.

docker run --rm myapp:1.0 df -h /dev/shm

This reveals the actual size currently allocated to the container's shared memory filesystem.

Increasing Shared Memory Size

For an application that genuinely needs more shared memory than the default provides, the size can be explicitly increased.

docker run -d --shm-size=1g myapp:1.0
Why Some Applications Specifically Need Larger Shared Memory

Certain applications — some database systems, machine learning frameworks performing significant inter-process data sharing — rely heavily on shared memory for performance reasons, and an insufficiently sized /dev/shm can cause these applications to fail or perform poorly.

docker run -d --shm-size=2g postgres:16

A database system handling substantial concurrent query processing might require a larger shared memory allocation than the conservative default provides.

Diagnosing a Shared Memory-Related Failure

An application failing with an error related to insufficient shared memory space is a specific, recognizable symptom suggesting --shm-size needs to be increased.

docker logs myapp

Error messages referencing /dev/shm or shared memory exhaustion specifically point toward this particular configuration needing adjustment.

Why Container Shared Memory Matters

Understanding that /dev/shm has a configurable, often conservative default size helps diagnose and resolve a specific, recognizable class of failure affecting applications that rely significantly on shared memory for their normal operation.