Repository navigation
[BUG] docker compose up --watch with sync+restart does not show logs after restart #11773
Description
Activity
Similar behavior happens when sending a
docker compose up --watchjob to the background and watching the output withdocker compose logs --followin another command window. The service logs show up until the service restart occurs, after which the logs command exits with code 0. One might expectdocker compose logs --followto show the sync/restart messages along with the rest of the output from the restarted (or terminated and started again) service.I think this happens when the number of running services drops to zero, even if temporarily for a restart. For example, if you start two services but one exits due to an error, this issue will occur when the other one is restarted.
I was able to work around this issue for now by keeping a dummy service alive at all times:
dummy-watch-workaround: image: alpine:latest init: true command: ["sh", "-c", "while true; do sleep 2; done"]Reacted by Loris Zinsou, Jared Johnson, ToshY, g-ouattara and Tor Arne Vestbø@dkaste I confirm. Let's say I have a
dband awebservice, thewebservice being the one I want to watch insync+restartmode.Just running
docker compose up --watch webends up with the terminal detaching from the service withweb-1 exited with code 0.But running
docker compose up --watch db webbehaves correctly.I'm still seeing this with
2.30.3❯ docker compose up --watch [+] Running 1/0 ✔ Container caddy-caddy-1 Running 0.0s ⦿ Watch enabled Attaching to caddy-1 ⦿ Syncing and restarting service "caddy" after 1 changes were detected caddy-1 | 2024/11/23 00:42:30.609 INFO shutting down apps, then terminating {"signal": "SIGTERM"} caddy-1 | 2024/11/23 00:42:30.609 WARN exiting; byeee!! 👋 {"signal": "SIGTERM"} caddy-1 | 2024/11/23 00:42:30.609 INFO http servers shutting down with eternal grace period caddy-1 | 2024/11/23 00:42:30.609 INFO admin stopped previous server {"address": "localhost:2019"} caddy-1 | 2024/11/23 00:42:30.609 INFO shutdown complete {"signal": "SIGTERM", "exit_code": 0} ⦿ service "caddy" restarted caddy-1 exited with code 0 ⦿ Syncing and restarting service "caddy" after 1 changes were detected caddy-1 | 2024/11/23 00:42:39.434 INFO shutting down apps, then terminating {"signal": "SIGTERM"} caddy-1 | 2024/11/23 00:42:39.434 WARN exiting; byeee!! 👋 {"signal": "SIGTERM"} caddy-1 | 2024/11/23 00:42:39.434 INFO http servers shutting down with eternal grace period caddy-1 | 2024/11/23 00:42:39.434 INFO admin stopped previous server {"address": "localhost:2019"} caddy-1 | 2024/11/23 00:42:39.434 INFO shutdown complete {"signal": "SIGTERM", "exit_code": 0} caddy-1 exited with code 0 ⦿ Watch disabled ❯After one or two changes to the Caddyfile, the service is restarted, and keeps running, but the watch disconnects.
services: caddy: image: torarnv/caddy build: . restart: unless-stopped ports: - "8080:80" develop: watch: - action: sync+restart path: ./Caddyfile target: /etc/caddy/CaddyfileCan someone please re-open this?
Same issue, occurrs from time to time after container recreation
Description
When running
docker compose up --watch, the logs for the service appear in the output.When specifying
sync+restartas the action on a file change, when a file is changed, the container restarts, but there are no more logs outputted. When runningdocker compose logs, you can see the app was restarted correctly and is still logging.This behaviour does not happen when using
rebuildas the action (although the logs aren't picked up straight away so the first logs are potentially missed).Expected behaviour is that when using
sync+restart, when a file is changed, the logs from the container continue to be shown in the output ofdocker compose up --watch.Steps To Reproduce
Dockerfile:
Contents of
srccan be anything.Docker Compose:
Running
docker compose up --watch, then saving a file insrcoutputs:➜ docker compose up --watch [+] Running 1/2 ✔ Network docker-compose-watch_default Created 0.1s ⠇ Container docker-compose-watch-app-1 Created 0.8s ⦿ Watch enabled Attaching to app-1 app-1 | restart app-1 | boop 0 app-1 | boop 1 app-1 | boop 2 app-1 | boop 3 app-1 | boop 4 app-1 | boop 5 app-1 | boop 6 ⦿ Syncing "app" after changes were detected [+] Restarting 1/1 ✔ Container docker-compose-watch-app-1 Started 0.6s app-1 exited with code 0When running
docker compose logs, it shows all the logs correctly.If you change
sync+restarttorebuildin the docker-compose file, and rundocker compose up --watch, and save a file, it now prints (most of) the logs correctly:➜ docker compose up --watch [+] Running 1/2 ✔ Network docker-compose-watch_default Created 0.1s ⠧ Container docker-compose-watch-app-1 Created 0.7s ⦿ Watch enabled Attaching to app-1 app-1 | restart app-1 | boop 0 app-1 | boop 1 app-1 | boop 2 app-1 | boop 3 app-1 | boop 4 app-1 | boop 5 ⦿ Rebuilding service "app" after changes were detected... app-1 | boop 6 ⦿ service "app" successfully built app-1 exited with code 0 app-1 has been recreated app-1 | boop 2 app-1 | boop 3 app-1 | boop 4 app-1 | boop 5 app-1 | boop 6Note that in the output, it misses the first few logs.
Doing a
docker compose logsonly shows the logs for the latest container.Compose Version
Anything else?
Feature introduction and demo