How would you limit how much disk a container can write?
AdvancedScenarioVolumes, storage and data
Answer
Situation read → One runaway container fills the host disk.
What I'd do →
docker run --storage-opt size=10Gworks on overlay2 only with an XFS backing filesystem mounted withpquota.- Alternatively put
/var/lib/dockeron its own filesystem or LV so it cannot starve the root disk. - Use
--tmpfs size=for scratch space and log rotation for logs. - In Kubernetes use
ephemeral-storagelimits.
Why → Docker has no portable per-container disk quota on ext4.
Interview tip → Monitor docker system df -v and node disk pressure.
More on Volumes, storage and data
A Postgres container was removed and the data is gone. How should it have been run?BeginnerBind mount or named volume for local development of a Node app?BeginnerHow do you back up a named volume?IntermediateTwo containers must share files. What are your options?BeginnerA container needs a writable temp area but the root filesystem is read-only.IntermediateMoving a database volume from one Docker host to another.Intermediate