C.W.K.
Stream
Lesson 04 of 05 · published

Bind Mounts — The Dev Loop Trick

~14 min · data, development

Level 0Container Curious
0 XP0/36 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Edit on host, run in container

Bind mounts map a host directory directly into the container. Files appear instantly on both sides. With a hot-reload-aware framework (uvicorn --reload, vite, nodemon), this gives you a real IDE on the host and a containerized runtime — without rebuilding the image on every code change.

The :ro modifier

Append :ro to make the mount read-only inside the container. Use this for config files, certificates, anything the container should consume but never modify. It's a lightweight defense-in-depth.

Code

Hot-reload dev container·bash
docker run -d --name api \
  -v $(pwd):/app \
  -v /app/__pycache__ \
  -p 8000:8000 \
  python:3.12-slim \
  sh -c "cd /app && pip install -r requirements.txt && uvicorn main:app --reload --host 0.0.0.0"

# Edit main.py on host. Save. uvicorn reloads inside the container.
# The anonymous volume on /app/__pycache__ keeps that ugly noise from
# polluting your host filesystem.
Read-only config·bash
docker run -d \
  -v $(pwd)/config.yaml:/app/config.yaml:ro \
  -v /etc/ssl/certs:/etc/ssl/certs:ro \
  myapp

External links

Exercise

Set up a bind-mount dev workflow for any Python or Node app: hot-reload on save. Make a code change without rebuilding the image and verify it shows up in the running container's behavior. Capture the run command.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.