Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 48/ 160
03. Storage, Volumes & Data Persistence

Read-Only Volumes & Mount Propagation (:ro, z, Z)

Lock mounts read-only and set SELinux/propagation flags correctly on shared hosts.

Advanced:ro · Propagation3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Make source trees or config mounts read-only by default, then add only the SELinux label and propagation mode the host topology proves necessary.

Think of it like…

Read-only is a locked plastic window, SELinux labels are visitor badges, and propagation is the rule for whether new doors appear through that window.

Where you’ve seen it

In practice, docker run --mount type=bind,src=$(pwd)/config,dst=/etc/acme,readonly,Z nginx:1.27 is the concrete move for this job: lock mounts read-only and set SELinux/propagation flags correctly on shared hosts. The release is not accepted until touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path confirms the result.

Words you’ll hear

:ro
The implementation control in docker run --mount type=bind,src=$(pwd)/config,dst=/etc/acme,readonly,Z nginx:1.27 for lock mounts read-only and set SELinux/propagation flags correctly on shared hosts.
Propagation
The result to observe with touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path, rather than infer from a successful command alone.
z/Z
The production boundary exposed when using :Z on a shared host directory used by several unrelated containers, or treating rprivate as a data integrity substitute for :ro.

Visual diagram

Loading interactive diagram

Theory & deep dive

:ro control path

The concrete mechanism is docker run --mount type=bind,src=$(pwd)/config,dst=/etc/acme,readonly,Z nginx:1.27. The observable result is touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path; if those disagree, inspect the runtime evidence before changing unrelated settings.

Lock mounts read-only and set SELinux/propagation flags correctly on shared hosts. Keep :ro, Propagation and z/Z in the same deployment record so the intent and the observed state cannot drift apart.

Concrete :ro setup

docker run --mount type=bind,src=$(pwd)/config,dst=/etc/acme,readonly,Z nginx:1.27

Key takeaway: Prove Propagation with touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path, not with command success alone.

z/Z failure boundary

A missing :Z on Fedora/RHEL gives an access-denied message that chmod will not fix, while permissive SELinux changes weaken the host for the wrong reason. rshared propagation can expose nested mounts from one container to a host tree. The narrow failure to design for is using :Z on a shared host directory used by several unrelated containers, or treating rprivate as a data integrity substitute for :ro.

Accept this compromise explicitly: Tighter labels and private propagation are safer; shared propagation is required only for controlled nested-mount workflows. The controlled check-touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: using :Z on a shared host directory used by several unrelated containers, or treating rprivate as a data integrity substitute for :ro.

Key takeaway: Tighter labels and private propagation are safer; shared propagation is required only for controlled nested-mount workflows.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: A missing :Z on Fedora/RHEL gives an access-denied message that chmod will not fix, while permissive SELinux changes weaken the host for the wrong reason. rshared propagation can expose nested mounts from one container to a host tree.

Make source trees or config mounts read-only by default, then add only the SELinux label and propagation mode the host topology proves necessary.
Key numbers at this step
Intent
:ro

When to use it & trade-offs

What it is

Suffix :ro or readonly=true blocks container writes through that mount. SELinux z relabels a bind path for sharing, while Z assigns a private label; mount propagation controls whether mount/unmount events cross shared mount boundaries and is separate from read/write.

Why it matters: A missing :Z on Fedora/RHEL gives an access-denied message that chmod will not fix, while permissive SELinux changes weaken the host for the wrong reason. rshared propagation can expose nested mounts from one container to a host tree.

When to reach for it

  • The fit is strongest for this job: lock mounts read-only and set SELinux/propagation flags correctly on shared hosts. Pair it with touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path in the runbook.
  • Production :ro changes should make Propagation observable through docker run --mount type=bind,src=$(pwd)/config,dst=/etc/acme,readonly,Z nginx:1.27, rather than trusting the runtime default.
  • Keep a rollback example for the case where using :Z on a shared host directory used by several unrelated containers, or treating rprivate as a data integrity substitute for :ro.

When to avoid or be careful

  • Do not accept command success while the system can still fail by using :Z on a shared host directory used by several unrelated containers, or treating rprivate as a data integrity substitute for :ro.
  • Avoid erasing z/Z protection merely to dodge this cost: “Tighter labels and private propagation are safer; shared propagation is required only for controlled nested-mount workflows”.
  • Do not replace the evidence path-touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path-with a screenshot or a mutable tag.

docker run --mount type=bind,src=$(pwd)/config,dst=/etc/acme,readonly,Z nginx:1.27: practical choices

Explicit :ro
Best for: Lock mounts read-only and set SELinux/propagation flags correctly on shared hosts, with a reviewed runbook.

Strengths: Suffix :ro or readonly=true blocks container writes through that mount. SELinux z relabels a bind path for sharing, while Z assigns a private label; mount propagation controls whether mount/unmount events cross shared mount boundaries and is separate from read/write.

Watch out: Tighter labels and private propagation are safer; shared propagation is required only for controlled nested-mount workflows.

Ambient default
Best for: Short-lived Propagation experiments with low blast radius.

Strengths: It can begin with docker run --mount type=bind,src=$(pwd)/config,dst=/etc/acme,readonly,Z nginx:1.27 and fewer surrounding controls.

Watch out: It silently accepts using :Z on a shared host directory used by several unrelated containers, or treating rprivate as a data integrity substitute for :ro, which makes the result hard to reproduce after promotion.

Managed z/Z
Best for: Teams that centralize z/Z policy across many workloads.

Strengths: A missing :Z on Fedora/RHEL gives an access-denied message that chmod will not fix, while permissive SELinux changes weaken the host for the wrong reason. rshared propagation can expose nested mounts from one container to a host tree.

Watch out: The platform adds an ownership and debugging layer; retain touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path as the direct check.

Interview signals & numbers to know

When this topic comes up

  • docker run --mount type=bind,src=$(pwd)/config,dst=/etc/acme,readonly,Z nginx:1.27
  • touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path
  • Failure signature: using :Z on a shared host directory used by several unrelated containers, or treating rprivate as a data integrity substitute for :ro
  • Trade-off: Tighter labels and private propagation are safer; shared propagation is required only for controlled nested-mount workflows.

Benchmarks & rules of thumb

1 write bit -
:ro denies mount writes
2 SELinux labels -
shared z versus private Z
rprivate -
default conservative propagation mode for many mounts

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful docker run --mount type=bind,src=$(pwd)/config,dst=/etc/acme,readonly,Z nginx:1.27 as proof and skipping touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path.
  • Using :Z on a shared host directory used by several unrelated containers, or treating rprivate as a data integrity substitute for :ro
  • Optimizing :ro without accepting that tighter labels and private propagation are safer; shared propagation is required only for controlled nested-mount workflows.

Likely interviewer follow-ups

  • Why does docker run --mount type=bind,src=$(pwd)/config,dst=/etc/acme,readonly,Z nginx:1.27 address :ro here rather than through application code?
  • How would you distinguish healthy Propagation from the failure “using :Z on a shared host directory used by several unrelated containers, or treating rprivate as a data integrity substitute for :ro” using touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path?
  • When would this trade-off-“Tighter labels and private propagation are safer; shared propagation is required only for controlled nested-mount workflows”-justify a different z/Z design?
Interview tip: Give one concrete operation-docker run --mount type=bind,src=$(pwd)/config,dst=/etc/acme,readonly,Z nginx:1.27-and one proof-touch /etc/acme/test from inside should fail; inspect HostConfig.Mounts and ls -Z the host path. Then name the boundary: using :Z on a shared host directory used by several unrelated containers, or treating rprivate as a data integrity substitute for :ro.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Read-Only Volumes & Mount Propagation (:ro, z, Z) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
In-Memory Storage with tmpfs Mounts for Sensitive/Temp Data
Next topic
Sharing Data Between Multiple Containers