docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
34.11k stars 5.25k forks source link

[BUG] docker compose up --watch with sync+restart ends up disconnecting from watch #12317

Open torarnv opened 1 day ago

torarnv commented 1 day ago

Description

Similar to https://github.com/docker/compose/issues/11773 I'm seeing docker compose up --watch disconnecting when the container is restarted:

❯ 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

❯
services:
  caddy:
    image: torarnv/caddy
    build: .
    restart: unless-stopped
    ports:
      - "8080:80"

    develop:
      watch:
        - action: sync+restart
          path: ./Caddyfile
          target: /etc/caddy/Caddyfile

Likely because it temporarily sees that there are no services running.

Adding a keep-alive workaround service "fixes" the issue:

dummy-watch-workaround:
  image: alpine:latest
  init: true
  command: ["sh", "-c", "while true; do sleep 2; done"]

Compose Version

2.30.3

ndeloof commented 23 hours ago

I tried to reproduce without success.

I'm using:

services:
  app1:
    build:
      dockerfile_inline: FROM nginx
    develop:
      watch:
        - action: sync+restart
          path: .
          target: /tmp

Can you please give it a try?