Docker cookbook · Beginner
Develop with Compose and live reload
Edit code on the host and see changes in the running container without rebuilding.
Approach
Use develop.watch in Compose: sync copies changed files into the container, rebuild rebuilds when
dependency files change. Run the app with its own auto-reload (uvicorn --reload, nodemon).
Solution
services:
api:
build: .
command: ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--reload"]
ports: ["127.0.0.1:8000:8000"]
develop:
watch:
- action: sync
path: ./src
target: /app/src
- action: rebuild
path: requirements.txt
docker compose watch
Pitfalls
- Bind-mounting the whole project over the image's dependency directory (hides
node_modulesor venv). - Publishing dev ports on all interfaces on shared networks.
Variations
- Classic bind mounts (
volumes: [./src:/app/src]) where file watching works across the mount. compose.override.yamlto keep development settings out of the production-like file.
Further reading: Compose watch
Reference: https://docs.docker.com/compose/how-tos/file-watch/
More Docker recipes
- Add a healthcheck to an HTTP service
- Build a layered image for a Spring Boot app
- Build a production image for a Node.js service
- Build a production image for a Python web app
- Build, cache and push images in GitHub Actions
- Build one image tag for amd64 and arm64
- Configure nginx from environment variables
- Make containers cope with dependencies that start slowly