Docker cookbook · Beginner

Develop with Compose and live reload

Edit code on the host and see changes in the running container without rebuilding.

Create a free account to save this page, take notes and track your progress. Sign in

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_modules or 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.yaml to 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

Was this page helpful?