Skip to content

[BUG] gw_priority has no effect if IPv6 is enabled on a network #13599

@pellaeon

Description

@pellaeon

Description

I have a service defined like this:

    networks:                                                                                                                                                                                                                                                                
      localnet:                                                                                                                                                                                        
        ipv4_address: 192.168.3.2                                                                                                                     
      localnet_vlan101:                                                                                                                                                                            
        gw_priority: 20                                                                                                                                                                                                                                                                       
        ipv4_address: 192.168.101.2             

                                             
networks:                                                                                                                                                   
  localnet:                                                                                                                                                 
    external: true                                                                                                                                          
  localnet_vlan101:                                                                                                                                         
    external: true                                                                                                                                                                                           

inspect localnet:

[
    {
        "Name": "localnet",
        "Id": "fba84ec49d6e562a8728e377ddf571c4f67ec731a7ed015acec984d88e83e2f7",
        "Created": "2025-11-22T16:13:57.561394744+08:00",
        "Scope": "local",
        "Driver": "macvlan",
        "EnableIPv4": true,
        "EnableIPv6": true,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.3.0/24",
                    "IPRange": "192.168.3.208/28",
                    "Gateway": "192.168.3.1"
                },
                {
                    "Subnet": "fd00:a:b:c::/64",
                    "IPRange": "fd00:a:b:c:1000::/72",
                    "Gateway": "fd00:a:b:c::1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Options": {
            "parent": "XXX"
        },
        "Labels": {},
        "Containers": {
            "933d24f5f1d288f0d0a57082cee201e89945ac7914eabced58edfb36b366c487": {
                "Name": "XXXXX",
                "EndpointID": "28a20bfc4846d475a16ea4adcb914193626d6161248f4dc206420933822cdadf",
                "MacAddress": "XXXXXX",
                "IPv4Address": "192.168.3.2/24",
                "IPv6Address": ""
            }
        },
        "Status": {
            "IPAM": {
                "Subnets": {
                    "192.168.3.0/24": {
                        "IPsInUse": 4,
                        "DynamicIPsAvailable": 16
                    },
                    "fd00:a:b:c::/64": {
                        "IPsInUse": 2,
                        "DynamicIPsAvailable": 72057594037927936
                    }
                }
            }
        }
    }
]

inspect localnet_vlan101:

[
    {
        "Name": "localnet_vlan101",
        "Id": "b71bf134bd7c5efce4af3c5c39243f31a99b24e326ee009be748f72ab77d87ae",
        "Created": "2026-01-05T12:02:48.380234715+08:00",
        "Scope": "local",
        "Driver": "macvlan",
        "EnableIPv4": true,
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.101.0/24",
                    "Gateway": "192.168.101.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Options": {
            "parent": "enp0s31f6.101"
        },
        "Labels": {},
        "Containers": {
            "933d24f5f1d288f0d0a57082cee201e89945ac7914eabced58edfb36b366c487": {
                "Name": "XXXXX",
                "EndpointID": "a986032a336513f14e762df7a62643fe5dbc9c8c4c3443e7a56a3b57e4b05088",
                "MacAddress": "XXXXX",
                "IPv4Address": "192.168.101.2/24",
                "IPv6Address": ""
            }
        },
        "Status": {
            "IPAM": {
                "Subnets": {
                    "192.168.101.0/24": {
                        "IPsInUse": 5,
                        "DynamicIPsAvailable": 251
                    }
                }
            }
        }
    }
]

Steps To Reproduce

  1. use the network config above
  2. start the service container
  3. exec shell in the container
  4. check default gateway with ip route show

In the above configuration, I expect the gateway to be set to 192.168.101.1 , since the network has higher gw_priority of 20 (vs 0, which is the default). However, the actual observed gateway is 192.168.3.1.

I tried replacing the localnet network with a non-IPv6 network, and the gateway is correctly set to 192.168.101.1

I suspect it might be NDP router advertisements influencing the container? but I thought they would only affect the IPv6 options?

Compose Version

Docker Compose version v5.0.2

Docker Environment

Client: Docker Engine - Community
 Version:    29.2.0
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.31.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v5.0.2
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 32
  Running: 17
  Paused: 0
  Stopped: 15
 Images: 77
 Server Version: 29.2.0
 Storage Driver: overlay2
  Backing Filesystem: zfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 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: dea7da592f5d1d2b7755e3a161be07f43fad8f75
 runc version: v1.3.4-0-gd6d73eb8
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.8.0-94-generic
 Operating System: Ubuntu 24.04.3 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 38.79GiB
 Name: XXXX
 ID: XXXXX
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
  ::1/128
 Live Restore Enabled: false
 Firewall Backend: iptables

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions