Skip to content

Conversation

@coderbirju
Copy link
Contributor

Current network inspect respone provides only container names
This PR adds other fields in the EndpointResource Struct

@coderbirju coderbirju closed this Jan 7, 2026
@coderbirju coderbirju reopened this Jan 7, 2026
@coderbirju coderbirju force-pushed the add-details-network-inspect branch from 2385db1 to eb356cf Compare January 9, 2026 00:27
@coderbirju coderbirju force-pushed the add-details-network-inspect branch from eb356cf to 365205b Compare January 21, 2026 22:35
@coderbirju
Copy link
Contributor Author

Apologies for the late reply, you're right we can skip the assert statements as the field existence is already validated through struct unmarshaling.

@haytok

@coderbirju coderbirju closed this Jan 29, 2026
@coderbirju coderbirju reopened this Jan 29, 2026
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
return helpers.Command("network", "inspect", data.Identifier("test-network"))
},
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no tests for the items added in this PR's changes. Should add assertions for IPv4Address, MacAddress, and IPv6Address.

Comment on lines +1006 to +1010
if ip4 := ip.To4(); ip4 != nil {
endpoint.IPv4Address = ip4.String()
} else if ip6 := ip.To16(); ip6 != nil {
// It's IPv6
endpoint.IPv6Address = ip6.String()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Docker uses CIDR notation, both IPv4 and IPv6 addresses should be displayed using CIDR.

Details

$ docker network inspect hoge | jq -r '.[].Containers'
{
  "1edfa9aa4b5fc45bd95d2b8c93da0a82096c81e84824a1590508766cd188ded8": {
    "Name": "test",
    "EndpointID": "6650361992e5f5f833d83f37e359f9309ac50dcc54f91f101c725287a83df025",
    "MacAddress": "52:90:e4:23:91:21",
    "IPv4Address": "172.21.0.2/16",
    "IPv6Address": ""
  }
}

Comment on lines +993 to +1010
endpoint.MacAddress = x.HardwareAddr

// Extract IPv4 and IPv6 addresses
for _, a := range x.Addrs {
ip, _, err := net.ParseCIDR(a)
if err != nil {
continue
}
if ip.IsLoopback() || ip.IsLinkLocalUnicast() {
continue
}

// Check for IPv4
if ip4 := ip.To4(); ip4 != nil {
endpoint.IPv4Address = ip4.String()
} else if ip6 := ip.To16(); ip6 != nil {
// It's IPv6
endpoint.IPv6Address = ip6.String()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current implementation, even when a container belongs to multiple networks, it displays the same MAC address and IPv4 address:

Details

nerdctl

$ sudo nerdctl network inspect hoge | jq -r '.[].Containers'
{
  "0fd9457578c4a886bf16e0251ab11c3748e82b7f19926b3a57178e4c3d25a2b5": {
    "Name": "test",
    "MacAddress": "6e:dc:83:0b:60:26",
    "IPv4Address": "10.4.7.2",
    "IPv6Address": ""
  }
}

$ sudo nerdctl network inspect fuga | jq -r '.[].Containers'
{
  "0fd9457578c4a886bf16e0251ab11c3748e82b7f19926b3a57178e4c3d25a2b5": {
    "Name": "test",
    "MacAddress": "6e:dc:83:0b:60:26",
    "IPv4Address": "10.4.7.2",
    "IPv6Address": ""
  }
}

docker

$ docker run -d --name test --network hoge --network fuga nginx

$ docker network inspect fuga | jq -r '.[].Containers'
{
  "1edfa9aa4b5fc45bd95d2b8c93da0a82096c81e84824a1590508766cd188ded8": {
    "Name": "test",
    "EndpointID": "a48d749f71c74ac38891d01064c61bdfebbb65a073b67eb8d9c7f913cf27d6a3",
    "MacAddress": "9a:43:51:15:58:4b",
    "IPv4Address": "172.22.0.2/16",
    "IPv6Address": ""
  }
}

$ docker network inspect hoge  | jq -r '.[].Containers'
{
  "1edfa9aa4b5fc45bd95d2b8c93da0a82096c81e84824a1590508766cd188ded8": {
    "Name": "test",
    "EndpointID": "6650361992e5f5f833d83f37e359f9309ac50dcc54f91f101c725287a83df025",
    "MacAddress": "52:90:e4:23:91:21",
    "IPv4Address": "172.21.0.2/16",
    "IPv6Address": ""
  }
}

Each network should display the corresponding interface's MacAddress, IPv4Address, and IPv6Address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants