A container needs a writable temp area but the root filesystem is read-only.
IntermediateScenarioVolumes, storage and data
Answer
Situation read → --read-only is a hardening best practice but apps still write to /tmp and /run.
What I'd do →
docker run --read-only --tmpfs /tmp:rw,noexec,nosuid,size=64m \
--tmpfs /run -v appdata:/var/lib/app myapp
Why → Writes land only in explicitly allowed places, and tmpfs is in memory so it vanishes on stop.
Interview tip → tmpfs counts against the container memory limit.
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?BeginnerMoving a database volume from one Docker host to another.IntermediateExplain how copy-on-write affects performance of a write-heavy container.Advanced