Skip to content

[BUG] --watch recreates unrelated containers on change #13046

@principis

Description

@principis

Description

Hi!

Since v2.37.1 when a change is made to a file where --watch is watching, the required services are recreated and restarted as expected. However other unrelated containers that are not watching that directory are also recreated, but not started. When that happens, it is possible to manually start those services, after which they don't exit anymore (as expected).

Also when that happens and if docker compose up --watch is canceled, it hangs indefinitely until the compose project is deleted.

I bisected between 2.37.0 and 2.37.1 and it looks like 9753079 introduced the bug.

Note that not all services are restarted, but only the once that use a dockerfile to build.

Steps To Reproduce

Extremely simplified example of our config

  1. example config
services:
  backend:
    build: &go-build
      context: .
      dockerfile: Dockerfile
      target: development
    command: "backend"
    develop:
      watch:
        - action: rebuild
          path: backend

  api:
    build: *go-build
    command: "api"
    develop:
      watch:
        - action: rebuild
          path: backend

  other-svc:
    build:
      context: ./other-svc
      dockerfile: Dockerfile

  frontend:
    build:
      context: .
      dockerfile: frontend.Dockerfile
      target: dev
    develop:
      watch:
        - action: rebuild
          path: ./frontend
  1. Run project
docker compose up --env-file .env up  --build --force-recreate --watch\
  1. Make a change in ./backend
  2. Watch services be recreated:
                                 ⦿ Rebuilding service(s) ["backend" "api"] after changes were detected...
[+] Building 0.0s (0/0)
                                 ⦿ service(s) ["backend" "api"] successfully built
other-svc-1 exited with code 0
other-svc-1 has been recreated
frontend-1 exited with code 0
frontend-1 has been recreated
backend-1 exited with code 2
backend-1 has been recreated
api-1 exited with code 0
api-1 has been recreated
  1. other-svc-1 and frontend-1 are not started.

Compose Version

Docker Compose version v2.38.1-desktop.1

I tested v2.36.2, v2.37.0 and v2.38.2

Docker Environment

Client:
 Version:    28.3.0
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  ai: Docker AI Agent - Ask Gordon (Docker Inc.)
    Version:  v1.8.0
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-ai
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.25.0-desktop.1
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-buildx
  cloud: Docker Cloud (Docker Inc.)
    Version:  v0.4.2
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-cloud
  compose: Docker Compose (Docker Inc.)
    Version:  v2.38.2-desktop.1
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.41
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-debug
  desktop: Docker Desktop commands (Docker Inc.)
    Version:  v0.1.11
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-desktop
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.29
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.4.0
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-init
  mcp: Docker MCP Plugin (Docker Inc.)
    Version:  v0.9.8
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-mcp
  model: Docker Model Runner (EXPERIMENTAL) (Docker Inc.)
    Version:  v0.1.33
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-model
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.18.1
    Path:     /Users/arthur.bols/.docker/cli-plugins/docker-scout

Server:
 Containers: 21
  Running: 16
  Paused: 0
  Stopped: 5
 Images: 20
 Server Version: 28.3.0
 Storage Driver: overlayfs
  driver-type: io.containerd.snapshotter.v1
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Discovered Devices:
  cdi: docker.com/gpu=webgpu
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
 runc version: v1.2.5-0-g59923ef
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.10.14-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 10
 Total Memory: 15.6GiB
 Name: docker-desktop
 ID: d3614a68-14a5-49aa-9c36-392ca46f3f11
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///Users/arthur.bols/Library/Containers/com.docker.docker/Data/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: DOCKER_INSECURE_NO_IPTABLES_RAW is set

Anything else?

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions