Skip to the workspace
Pebellslearn by building
Data Persistence  ›  Capstone Project

Bind Mounts

Bind Mounts 14 minA bind mount maps a specific folder or file from the host into the container, which is ideal for live-editing code in development but ties the container to the host's layout and permissions.

docker / Bind Mounts

Explore each scene at your own pace.

01 · The rule

The rule

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.0

The 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 /app is covered by your folder while the mount is in place. In development that is exactly the point.
  • :ro makes 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.sock gives 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.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.