moby: docker network inspect only returns containers local to current node

Output of docker version:

$ docker version
Client:
 Version:      1.12.0-rc2
 API version:  1.24
 Go version:   go1.6.2
 Git commit:   906eacd
 Built:        
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.0-rc2
 API version:  1.24
 Go version:   go1.6.2
 Git commit:   906eacd
 Built:        
 OS/Arch:      linux/amd64

Output of docker info:

$ docker info
Containers: 7
 Running: 2
 Paused: 0
 Stopped: 5
Images: 7
Server Version: 1.12.0-rc2
Storage Driver: overlay
 Backing Filesystem: xfs
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: host null bridge overlay
Swarm: active
 NodeID: 1120tlfjfl8hb8ej0vl4jf0uk
 IsManager: Yes
 Managers: 1
 Nodes: 3
 CACertHash: sha256:e40f879fdf091f783caae7790db4defc1e1828bc31101029ac18cfb2fdbb56b5
Runtimes: default
Default Runtime: default
Security Options: seccomp
Kernel Version: 3.10.0-327.10.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 991.7 MiB
Name: manager1
ID: VVLS:3SXS:G7IZ:I6MG:DOQ6:VDI5:YWPO:E3XF:ZPMH:RP7C:RBAN:W2SG
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: bridge-nf-call-ip6tables is disabled
Insecure Registries:
 127.0.0.0/8

This is more of an enhancement, but I think in the context of a swarm/cluster, I may want to list the containers participating in the entire network, not just on the current node. And see which nodes the containers are running on.

$ docker network inspect mynetwork
[
    {
        "Name": "mynetwork",
        "Id": "8ftib96dxooksdj8b4chprun2",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "75.1.0.0/16",
                    "Gateway": "75.1.0.1"
                }
            ]
        },
        "Internal": false,
        "Containers": {
            "8ec6bc3e3cbb2d22d2c66859b9051c99ab7bd753172a57b89b679b7c80787365": {
                "Name": "frontend.1.5natc1sik5v7i8174h3jzazdo",
                "EndpointID": "cef522ff38f26e9a7284bc273a1f083e560baf297f11050c282ec42688047f34",
                "MacAddress": "02:42:4b:01:00:06",
                "IPv4Address": "75.1.0.6/16",
                "IPv6Address": ""
            },
            "b3455bee301a3f700276ff54bba87c2c3418dbfff6c5c117c46c12c23a027d16": {
                "Name": "redis.1.dsej2jdxc9g2qlvm39m19vn60",
                "EndpointID": "93d447d8d90207aca66e7766e2e5537a2525bb8f529a508c67fb27bfd92dbb7a",
                "MacAddress": "02:42:4b:01:00:08",
                "IPv4Address": "75.1.0.8/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "257"
        },
        "Labels": {}
    }
]

Describe the results you expected: See all containers on the network and the node where they’re running regardless of the current node.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

The current implementation of checking services associated with a network is a really expensive operation and kind of a hack, because we don’t have an easy way in swarmkit to map network->service. It’s definitely possible it just might not be ideal until we can do network->service mapping correctly.

@persunde make sure to look at the tasks under Services, not the containers list; the tasks represent services connected to the network (which may not be local); containers will only contain containers on the current node.

For example;

docker network inspect mynet -v
[
    {
        "Name": "mynet",
        "Id": "xr1vyuixwvbzj1607r63tr7bk",
        "Created": "2022-08-19T15:53:45.051778821Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.0.0/24",
                    "Gateway": "10.0.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "c391b6ead0925762132cec2114e6c564b56f88b5fe582f92032e982aa9fdbe75": {
                "Name": "testing.3.ybbtitbu2ih4dsnh67go7afcw",
                "EndpointID": "774a7e17dfaeb417c9393ecfa6160e9b76fa480e69529a12dac6967623db65b8",
                "MacAddress": "02:42:0a:00:00:04",
                "IPv4Address": "10.0.0.4/24",
                "IPv6Address": ""
            },
            "lb-mynet": {
                "Name": "mynet-endpoint",
                "EndpointID": "372d846f8960d7a3005f1b3a4661fcdce9b691a6eb653cb82aaf5af3d62a2405",
                "MacAddress": "02:42:0a:00:00:07",
                "IPv4Address": "10.0.0.7/24",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.driver.overlay.vxlanid_list": "4097"
        },
        "Labels": {},
        "Peers": [
            {
                "Name": "5b12e95f8b48",
                "IP": "10.133.83.180"
            },
            {
                "Name": "f4af3629c59a",
                "IP": "10.133.77.81"
            },
            {
                "Name": "519d1bbb8317",
                "IP": "10.133.84.218"
            }
        ],
        "Services": {
            "testing": {
                "VIP": "10.0.0.2",
                "Ports": [],
                "LocalLBIndex": 256,
                "Tasks": [
                    {
                        "Name": "testing.3.ybbtitbu2ih4dsnh67go7afcw",
                        "EndpointID": "774a7e17dfaeb417c9393ecfa6160e9b76fa480e69529a12dac6967623db65b8",
                        "EndpointIP": "10.0.0.4",
                        "Info": {
                            "Host IP": "10.133.83.180"
                        }
                    },
                    {
                        "Name": "testing.1.siesp65lugjxyitam25ixr9do",
                        "EndpointID": "949ddfc77c0d5a15fa5e719d8f43c4625ade2e95e2aa29f6a88d9fd04edddfd4",
                        "EndpointIP": "10.0.0.5",
                        "Info": {
                            "Host IP": "10.133.84.218"
                        }
                    },
                    {
                        "Name": "testing.2.7avts9h56covj8419686ztfo6",
                        "EndpointID": "a886dda37b77ec47396aa52df45fde34bc4a0fd6bfda90c54777ba91c50664af",
                        "EndpointIP": "10.0.0.3",
                        "Info": {
                            "Host IP": "10.133.77.81"
                        }
                    }
                ]
            }
        }
    }
]

Hi, we are seeing this exact same behavior using docker 18.06. I read the comments above and bit confused. So what’s the upshot of all this? Is it expected behavior of docker that network inspect only lists containers hosted on the node from which the command is executed?

not able to reproduce this; on a manger that doesn’t have any containers running, I can see the containers that are attached to the network, but are running on other nodes

If you do docker network inspect <network-name> -v you should be able to see the services info as well. The Host IP field for each task shows the swarm node running the task.

Example:

$ docker network inspect ddrnet1 -v
[
    {
        "Name": "ddrnet1",
        "Id": "mrzmpv49u8nmrcm4h4lzbk8mb",
        "Created": "2018-02-08T17:35:13.215637022Z",
        "Scope": "swarm",
        "Driver": "overlay",
        "EnableIPv6": false,
        .
        .
        .
        "Containers": {
            "0cd71e016244199abfe6fe5f1df8bdd4857e3a2d0b7109705c6e31f0afc1404e": {
                "Name": "nginx1.5.kvm83j4en2aexfv3eihx7ca8g",
                "EndpointID": "c923980c7911cbb3025ab1cf830bd347da553b2294731bbe4376f3d097d00353",
                "MacAddress": "02:42:0a:00:00:0b",
                "IPv4Address": "10.0.0.11/24",
                "IPv6Address": ""
            },
            "7104de5ff971245e50454d5a43323dcc0a432fde45a2455d1a67419af2d8306a": {
                "Name": "nginx1.2.u858twpno4ujla4akzcundjzv",
                "EndpointID": "4e2989db1f131cba004966855b368b0dd03be63b2bbd9ede15f27559e9c89257",
                "MacAddress": "02:42:0a:00:00:08",
                "IPv4Address": "10.0.0.8/24",
                "IPv6Address": ""
            }
        },
        .
        .
        .
        "Services": {
            "nginx1": {
                "VIP": "10.0.0.5",
                "Ports": [],
                "LocalLBIndex": 256,
                "Tasks": [
                    {
                        "Name": "nginx1.2.u858twpno4ujla4akzcundjzv",
                        "EndpointID": "4e2989db1f131cba004966855b368b0dd03be63b2bbd9ede15f27559e9c89257",
                        "EndpointIP": "10.0.0.8",
                        "Info": {
                            "Host IP": "10.0.0.4"
                        }
                    },
                    {
                        "Name": "nginx1.6.j2ui1t27tf1irdghkvn9zbpi8",
                        "EndpointID": "658a4a40684eebbe140a0f28c21666374b4223b3053e763ca16938ec58c5f309",
                        "EndpointIP": "10.0.0.6",
                        "Info": {
                            "Host IP": "10.0.0.6"
                        }
                    },
                    {
                        "Name": "nginx1.1.5dftngubm6mpea1rpk8s8jk1o",
                        "EndpointID": "bf80175b72526c5622ce4a1de1044e29eede0d86a72b66cf6fcdc1887ff408dd",
                        "EndpointIP": "10.0.0.7",
                        "Info": {
                            "Host IP": "10.0.0.5"
                        }
                    },
                    {
                        "Name": "nginx1.5.kvm83j4en2aexfv3eihx7ca8g",
                        "EndpointID": "c923980c7911cbb3025ab1cf830bd347da553b2294731bbe4376f3d097d00353",
                        "EndpointIP": "10.0.0.11",
                        "Info": {
                            "Host IP": "10.0.0.4"
                        }
                    },
                    {
                        "Name": "nginx1.3.xrudl156h5o21lk2wiaacmrmg",
                        "EndpointID": "ef58f08c34ca17f22bcdaa8f93fed767a03fc830fd14d267d7054460bcbf16bf",
                        "EndpointIP": "10.0.0.9",
                        "Info": {
                            "Host IP": "10.0.0.6"
                        }
                    },
                    {
                        "Name": "nginx1.4.kcbv3ooaxyy3uebgp3h6qc9hp",
                        "EndpointID": "3fd1cde738a333ef4669e0288ce29bbfbb01dd3c59a15dd28595b6beb20ccef1",
                        "EndpointIP": "10.0.0.10",
                        "Info": {
                            "Host IP": "10.0.0.5"
                        }
                    }
                ]
            }
        }
    }
]