Read-Only Volumes & Mount Propagation (:ro, z, Z)
Lock mounts read-only and set SELinux/propagation flags correctly on shared hosts.
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.27for 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
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.
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, 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.
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.
How it works, step by step
Step 1 of 41. 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.
- 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 pathin 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
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.
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.
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.27as proof and skippingtouch /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.27address :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?
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
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.