Develop with read-only source mounts
A bind mount connects a particular host path to a container path. For development, a source file can change without rebuilding the image. Here a worker reads a synthetic message from /source/message.txt. The source directory contains only this lab file and is mounted read-only. Edit the host file, then read it again from the container. A read-only mount prevents ordinary container writes to that mount, not host edits. It can hide files that the image originally placed at the target. Prefer a narrow source directory over your home directory. On Desktop the file-sharing layer, permissions and filesystem notifications can behave differently from native Linux.
Read the development model
services: worker: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sleep - '300' network_mode: none volumes: - type: bind source: ./src target: /source read_only: true bind: create_host_path: falseManual lab
Manual lab only, not browser execution. Use a fresh approved disposable Linux VM with external egress blocked and a local Docker context. Check docker context show, docker version and docker compose version; verify the exact options and fields. Preload and verify a native-platform BusyBox 1.37 image digest, entrypoint and required applets; the tag is mutable. For builds verify a local Buildx docker driver using the reviewed base, with network blocked. Check all bm-v14 project and image names are unused and inherited Compose settings do not interfere. Use only a disposable copy of the supplied synthetic files; confirm UID 10001 can read source files. No public ports, external pulls/pushes, real secrets, broad host mounts or privileged containers. Run each line separately, stop on unexpected failures, clean only the lab and dispose of the VM. All results are predictions. Before Engine requests, verify the effective endpoint including DOCKER_HOST and DOCKER_CONTEXT; a project name does not select the daemon. Review inherited COMPOSE_ENV_FILES, COMPOSE_DISABLE_ENV_FILE, profile and project settings. Use a clean shell and the exact fixture directory. Inspect only synthetic config, logs and files. If a build is required, verify the effective builder can resolve the approved local base without egress; stop if build fails, never reuse a stale tag.
Open lab-fixtures/docker-compose-development/01-source-mounts/ in the extracted archive and run from a disposable copy of that folder.
docker compose -f compose.yaml -p bm-v14-source-mounts config --quietdocker compose -f compose.yaml -p bm-v14-source-mounts up -d --no-build --pull neverdocker compose -f compose.yaml -p bm-v14-source-mounts exec -T worker cat /source/message.txtprintf "edited-v14\n" > src/message.txtdocker compose -f compose.yaml -p bm-v14-source-mounts exec -T worker cat /source/message.txt# Expected failure: the mount is read-onlydocker compose -f compose.yaml -p bm-v14-source-mounts exec -T worker sh -c 'printf "unexpected\n" > /source/message.txt'cat src/message.txtdocker compose -f compose.yaml -p bm-v14-source-mounts exec -T worker cat /source/message.txtprintf "first-v14\n" > src/message.txtThe first read should show first-v14 and the second edited-v14. A write to the mounted file from the container should fail. This demonstrates visibility of edits, not automatic application reload. After the failed write, re-read the file from both host and running container before restoring it. Both should still show edited-v14. Check mount metadata for read-only mode; a failure from unrelated permissions is not evidence that the mount is read-only.
Clean only the named lab projects; no global prune or force removal. Retain the reviewed base image. A failed cleanup requires VM disposal and review.
docker compose -f compose.yaml -p bm-v14-source-mounts downdocker compose -f compose.yaml -p bm-v14-source-mounts ps -aCommon mistake
Changing source files does not necessarily restart a process or reload a framework. Check the application behavior separately. Never mount unrelated files to fix permissions.
Manual practice
Predict what happens after restoring the host text. Explain why the image itself remains unchanged.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Develop with read-only source mounts — Knowledge check
Reason about development workflows and their effects.
What changes after a host edit?
What does read_only restrict?
Does a mount guarantee hot reload?