Docker Compose Watch: live updates while you code
Select an icon to see what it is.
Step 6 of 6
Watch or bind mount?
A bind mount shows the host directory inside the container, so changes appear at once with no copying. Watch copies files instead, which suits cases where a bind mount is slow, such as a tree with many small files, or where you want to restart or rebuild on certain changes. Both are for development, not for production.
PrevNext
Comparison
bind mount: the same directory, live, no Compose rule neededwatch sync: copies changed files, can also restart or rebuildwatch rebuild: the only way to get a changed Dockerfile into the image
Try it yourself
Run the project with watch, then edit files in another terminal. This needs a recent Docker Compose. Stop it with Ctrl-C, then run docker compose down.
$ mkdir -p html && echo 'version 1' > html/index.html$ printf 'events {}\nhttp {\n include /etc/nginx/mime.types;\n server {\n listen 80;\n root /usr/share/nginx/html;\n }\n}\n' > nginx.conf$ printf 'FROM nginx\nCOPY html /usr/share/nginx/html\nCOPY nginx.conf /etc/nginx/nginx.conf\n' > Dockerfile$ cat > compose.yaml <<'EOF' name: shop services: web: build: . ports: - "8080:80" develop: watch: - action: sync path: ./html target: /usr/share/nginx/html - action: sync+restart path: ./nginx.conf target: /etc/nginx/nginx.conf - action: rebuild path: ./Dockerfile networks: default: ipv4_address: 172.18.0.2 networks: default: name: shop-net ipam: config: - subnet: 172.18.0.0/16 EOF$ docker compose up --watch$ # in a second terminal: curl http://localhost:8080 ; echo 'version 2' > html/index.html ; curl http://localhost:8080$ docker compose down