Interview Q&A / Docker & Kubernetes

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What does docker run --read-only do and how do you handle apps that need to write?

SHORT ANSWER

--read-only makes the container's root filesystem unwritable, so malware cannot modify binaries or drop files. Give the app writable tmpfs or volume mounts only for the paths it truly needs, such as /tmp.

Explain it simply

A printed question paper cannot be changed by students; they get a separate answer sheet for writing. A read-only root filesystem is the printed paper, and tmpfs or volumes are the answer sheets.

With --read-only, any write to the image filesystem fails with 'Read-only file system'. An attacker who gets code execution cannot replace your binary, edit config or install tools. Real apps still need some writable space: temp files, PID files, caches. Add --tmpfs /tmp or mount a volume at that exact path. Run the app, watch the errors in the logs, and add only the paths it complains about. Nginx, for instance, needs /var/cache/nginx and /var/run writable.

Kubernetes equivalent: securityContext.readOnlyRootFilesystem: true with emptyDir volumes for writable paths.

Example

bash
docker run -d --read-only \
  --tmpfs /tmp --tmpfs /var/cache/nginx --tmpfs /var/run \
  -p 8080:80 nginx

What to say in the interview

"--read-only locks the root filesystem so attackers cannot change binaries or config. I allow writes only through tmpfs or volume mounts on specific paths the app needs, found by checking error logs."

Common mistakes

  • Giving the whole app directory a writable volume and defeating the purpose.

#docker#security#filesystem

Related questions

Practise more Docker & Kubernetes questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Docker & Kubernetes quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.