Docker read-only mounts: protect input files
Lab prerequisites
Use only an approved disposable, offline Linux VM with a local Docker Engine, ordinary local volume driver, and reviewed preloaded busybox:1.37 (record its digest, platform, exact Engine version and required utilities first). Verify the active Docker context and endpoint; every bm-v06 resource name in the lesson must be unused before starting. Never reuse a pre-existing volume. Use a dedicated lab shell, run commands individually in order, and stop on unexpected errors (the explicitly labeled negative tests are exceptions). Only delete resources you created after confirming their identity. All outputs are expected, not observed; these are manual labs, not ByteMind runnable editors. Before contacting the Engine, verify the effective local endpoint including DOCKER_HOST, DOCKER_CONTEXT and CLI overrides. Recheck the approved local image ID and native platform; if the recorded digest is unavailable, report it as unknown rather than inventing one. Use owner-set resource and time limits. If prerequisites cannot be confirmed, do the paper exercise instead. Check that the approved fixture has no declared image volumes and that the synthetic destinations and file names are unused. The bind-mount lesson alone uses a fresh host directory; do not extend it to other paths.
Limit what the application can change
A report generator may need to read a template but should not be able to change it. Mount its template directory with readonly (or ro) and keep reports elsewhere. A read-only mount restricts writes through that specific mount; it does not make the entire container filesystem immutable or prevent other authorized writers from modifying the underlying data.
Seed an input and read it
Create a fresh volume and initialize a synthetic input. A new container mounts it read-only and reads it. Expect template-v1. The same container can write a disposable result to its own /tmp because the restriction applies only to /input.
docker volume create bm-v06-templatedocker run --rm --pull=never --network none -v bm-v06-template:/input busybox:1.37 sh -c 'printf "template-v1\n" > /input/note'docker run --rm --pull=never --network none --mount type=volume,src=bm-v06-template,dst=/input,readonly busybox:1.37 sh -c 'cat /input/note && printf "report\n" > /tmp/report && cat /tmp/report'Verify the denied operation
The following is an intentionally rejected write, not a command expected to succeed. The shell should report a write failure and Docker should return a nonzero exit status. Read the file again to confirm template-v1 remains. Do not use a privilege override to make the negative test pass. Remove the lab volume only after checking the original content. A nonzero Docker exit status alone is not enough: confirm the shell reached the write and reported a read-only filesystem error. If the write unexpectedly succeeds or a daemon error occurs, stop and retain the evidence.
docker run --rm --pull=never --network none -v bm-v06-template:/input:ro busybox:1.37 sh -c 'printf "changed\n" > /input/note'printf 'status=%s\n' "$?"docker run --rm --pull=never --network none -v bm-v06-template:/input:ro busybox:1.37 cat /input/notedocker volume rm bm-v06-templateManual practice
Choose which paths a report generator should mount read-only and which should be writable. Explain how a second writer could still alter the input.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Docker read-only mounts: protect input files — Knowledge check
Apply the concepts from this lesson.
Which option makes a -v volume mount read-only?
Can a process write to an unrelated writable /tmp directory when /input is mounted read-only?
After confirming the write was attempted inside the container, what verifies the negative test most directly?