Diagnosis
docker logs my-container
# [error] Failed to write to /tmp/cache.json: Read-only file system
The application expects to write to /tmp. read_only: true
prevents that.
Fix
services:
api:
image: myorg/api:1.0.0
read_only: true
tmpfs:
- /tmp
- /var/cache/myapp
volumes:
- app-data:/var/lib/myapp
security_opt:
- no-new-privileges:true
cap_drop: [ALL]
cap_add: [NET_BIND_SERVICE]
Each writable path is now explicit. The root filesystem stays read-only; the writable paths are isolated to tmpfs or volumes.