Skip to content

[BUG] network_mode: service always recreates the container since v5.2.0 #13878

Description

@tanasegabriel

Description

Since v5.2.0 was released, containers that are using another service's network are being recreated with each up command, even though the config (at least the one defined by the user) never changes.

Switching to network_mode: container mitigates this.

Likely related to #13830

Steps To Reproduce

Config

services:
  net_parent:
    container_name: net_parent
    image: alpine
    command: tail -f /dev/null
    stop_grace_period: 0s

  net_dependant:
    extends:
      service: net_parent
    container_name: net_dependant
    network_mode: service:net_parent

Steps

  1. Run docker compose up -d && docker compose up -d --dry-run. The second invocation should have shown no containers to recreate, but that is not the case:
$ docker compose up -d && docker compose up -d --dry-run
[+] up 3/3
 ✔ Network test_compose_default Created                                                                            0.1s
 ✔ Container net_parent         Started                                                                            0.3s
 ✔ Container net_dependant      Started                                                                            0.4s
[+] up 3/3
 ✔ Container net_parent                 Running                                                                    0.0s
 ✔ Container net_dependant              Recreated                                                                  0.0s
 ✔ Container 196e7f5de123_net_dependant Started                                                                    0.0s
  1. Tear down, switch to network_mode: container:net_parent and re-run docker compose up -d && docker compose up -d --dry-run
-     network_mode: service:net_parent
+     network_mode: container:net_parent
$  docker compose up -d && docker compose up -d --dry-run
[+] up 3/3
 ✔ Network test_compose_default Created                                                                            0.1s
 ✔ Container net_dependant      Started                                                                            0.5s
 ✔ Container net_parent         Started                                                                            0.3s
[+] up 2/2
 ✔ Container net_dependant Running                                                                                 0.0s
 ✔ Container net_parent    Running                                                                                 0.0s

Compose Version

Docker Compose version v5.2.0

Docker Environment

Client: Docker Engine - Community
 Version:    29.6.0
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.35.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v5.2.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose
  model: Docker Model Runner (Docker Inc.)
    Version:  v1.2.4
    Path:     /usr/libexec/docker/cli-plugins/docker-model

Server:
 Containers: <int>
  Running: <int>
  Paused: <int>
  Stopped: <int>
 Images: <int>
 Server Version: 29.6.0
 Storage Driver: overlayfs
  driver-type: io.containerd.snapshotter.v1
 Logging Driver: json-file
 Cgroup Driver: systemd
 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: e53c7c1516c3b2bff98eb76f1f4117477e6f4e66
 runc version: v1.3.6-0-g491b69ba
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 7.0.0-1011-raspi
 Operating System: Ubuntu 26.04 LTS
 OSType: linux
 Architecture: aarch64
 CPUs: 4
 Total Memory: 7.746GiB
 Name: <hostname>
 ID: <id>
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false
 Firewall Backend: iptables
  EnableUserlandProxy: true
  UserlandProxyPath: /usr/bin/docker-proxy

Anything else?

No response

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions