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.