Skip to content

[BUG] Docker Compose watch fails to replace new containers if change affects multiple containers #12427

Open
@joaomcarlos

Description

Description

Hi,

I am having an issue where I have setup watch rules for changes in a common dependency should trigger a container rebuild on all services that depend upon it.

However, once I do this and I make a simple change on "lib common", the rebuild will eventually fail with the message WARN[0171] Error handling changed files for service <service1>: Error response from daemon: Error when allocating new name: Conflict. The container name "/<proj>-<service1>-1" is already in use by container "862f5bff1233aebc766fe966b06cc0e491eedbf4f475cd169fa7c6af10ff752b". You have to remove (or rename) that container to be able to reuse that name

Steps To Reproduce

The stage
Have a project with a packages/common and several project/service1/2/3/4/etc projects.

At the root, there is a single docker-compose.yml with a list of included docker-compose.yml entries, one for each service.

Each of the services docker compose has a watch rule for rebuild when lib-common code changes.

    develop:
      watch:
        - action: sync+restart
          path: api
          target: /app/api
        - action: rebuild
          path: pdm.lock
          target: /app/pdm.lock
        - action: rebuild
          path: ../../packages/common/common

Steps

1- docker compose watch to build and watch all services
2- Change anything in the common package, so that it triggers a multi-service rebuild
3- Watch and wait until all services finish build
4- Watch as multiple error messages appear, as it fails to replace the running containers

The error
When building finishes, I get multiple:

WARN[0171] Error handling changed files for service <service1>: Error response from daemon: Error when allocating new name: Conflict. The container name "/<proj>-<service1>-1" is already in use by container "862f5bff1233aebc766fe966b06cc0e491eedbf4f475cd169fa7c6af10ff752b". You have to remove (or rename) that container to be able to reuse that name

And none of those services that error will now be running. There will be multiple stopped containers with "uuid" prefixes and one or none of the services that build will be running.

Compose Version

➜ docker compose version
Docker Compose version 2.32.0



➜ docker-compose version
Docker Compose version v2.31.0-desktop.2

Docker Environment

➜ docker info
Client:
 Version:    27.4.0
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  ai: Ask Gordon - Docker Agent (Docker Inc.)
    Version:  v0.5.1
    Path:     /Users/joaoc/.docker/cli-plugins/docker-ai
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.19.2-desktop.1
    Path:     /Users/joaoc/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  2.32.0
    Path:     /opt/homebrew/lib/docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.37
    Path:     /Users/joaoc/.docker/cli-plugins/docker-debug
  desktop: Docker Desktop commands (Beta) (Docker Inc.)
    Version:  v0.1.0
    Path:     /Users/joaoc/.docker/cli-plugins/docker-desktop
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     /Users/joaoc/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.27
    Path:     /Users/joaoc/.docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.5
    Path:     /Users/joaoc/.docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.4.0
    Path:     /Users/joaoc/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/joaoc/.docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.15.1
    Path:     /Users/joaoc/.docker/cli-plugins/docker-scout

Server:
 Containers: 21
  Running: 12
  Paused: 0
  Stopped: 9
 Images: 24
 Server Version: 27.4.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
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 472731909fa34bd7bc9c087e4c27943f9835f111
 runc version: v1.1.13-0-g58aa920
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.10.14-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 12
 Total Memory: 7.653GiB
 Name: docker-desktop
 ID: 275e806e-6b09-4a6a-86e4-db4fb710c1a6
 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/joaoc/Library/Containers/com.docker.docker/Data/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile

Anything else?

No response

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions