Bind Mounts
While developing quicknotes, rebuilding the image after every one-line change is painfully slow. You want to edit app.py in your editor and have the running container see the change at once. That needs the container to look directly at a folder on your machine: a bind mount.
The rule
A bind mount is a window from the container onto a host folder.
A bind mount maps an existing file or folder on the host to a path inside the container. There is no copy: both sides see the same files, live.
docker run -d --name notes-dev -p 8080:5000 \
-v "$PWD":/app \
quicknotes:1.0The left side of -v is now a path, so this is a bind mount. The --mount form is --mount type=bind,source="$PWD",target=/app. Things to know:
- It hides what was there. The code the image copied into
/appis covered by your folder while the mount is in place. In development that is exactly the point. :romakes it read-only:-v /etc/quicknotes/config.toml:/app/config.toml:ro. The app can read the file but never change it.- Permissions come from the host. The kernel compares numeric UIDs, so if the container's user has a different UID from the files' owner, it may be refused.
- It ties the container to one machine's layout. The path must exist on that host, which is why bind mounts suit development and host-provided config, while volumes suit application data.
- It can reach anything. Mounting
/or/var/run/docker.sockgives a container great power over the host. Mount only what you need.
With the code bind-mounted, you can make the app reload when files change. That is a job for your framework's development server, not for Docker; Docker just makes the edits visible.
The shortcut
Choose by asking who owns the data's location? If the host owns it (your source code, a config file already on the server), use a bind mount. If Docker should own it (app data that must just persist), use a named volume.
Live source code
Lives in your project folder; you edit it on the host. Host owns it:
-v "$PWD":/app.
Drills
Answer fast — trust the rule.
Which flag creates a bind mount?
The image has code in /app, and you bind-mount your project folder onto /app. What does the container see there?
How do you stop a container changing a bind-mounted config file?
For quicknotes' production notes data on a server, which is the better fit?
A bind-mounted folder gives "permission denied" inside the container although the names look right. What is the likely cause?
Remember
- A bind mount is a window from the container onto a host folder: same files, live.
- Shortcut: host owns the location → bind mount; Docker should own it → named volume.
- Trap: mounts hide the image's files at the target, permissions follow numeric UIDs, and broad mounts give broad power.
