diff --git a/libpod/networking_common.go b/libpod/networking_common.go index b892e60e9e..03bd8d99d0 100644 --- a/libpod/networking_common.go +++ b/libpod/networking_common.go @@ -325,7 +325,9 @@ func resultToBasicNetworkConfig(result types.StatusBlock) define.InspectBasicNet if config.IPAddress == "" { config.IPAddress = netAddress.IPNet.IP.String() config.IPPrefixLen = size - config.Gateway = netAddress.Gateway.String() + if netAddress.Gateway != nil { + config.Gateway = netAddress.Gateway.String() + } } else { config.SecondaryIPAddresses = append(config.SecondaryIPAddresses, define.Address{Addr: netAddress.IPNet.IP.String(), PrefixLength: size}) } @@ -334,7 +336,9 @@ func resultToBasicNetworkConfig(result types.StatusBlock) define.InspectBasicNet if config.GlobalIPv6Address == "" { config.GlobalIPv6Address = netAddress.IPNet.IP.String() config.GlobalIPv6PrefixLen = size - config.IPv6Gateway = netAddress.Gateway.String() + if netAddress.Gateway != nil { + config.IPv6Gateway = netAddress.Gateway.String() + } } else { config.SecondaryIPv6Addresses = append(config.SecondaryIPv6Addresses, define.Address{Addr: netAddress.IPNet.IP.String(), PrefixLength: size}) } diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at index daedb4e02f..aed21e3f93 100644 --- a/test/apiv2/20-containers.at +++ b/test/apiv2/20-containers.at @@ -366,6 +366,18 @@ t POST containers/${cid_top}/start 204 t GET containers/${cid_top}/json 200 \ .State.Status="running" +# check that gateway is empty not "", https://github.com/containers/podman/issues/28705 +podman network create testnet --internal --disable-dns +podman run --name testcon --network testnet -d $IMAGE top + +t GET containers/testcon/json 200 \ + .NetworkSettings.Networks.testnet.Gateway="" \ + .NetworkSettings.Networks.testnet.IPAddress~10\..* \ + .NetworkSettings.Networks.testnet.IPPrefixLen=24 + +podman rm -f -t0 testcon +podman network rm testnet + # 0 means unlimited, need same with docker t GET containers/json?limit=0 200 \ .[0].Id~[0-9a-f]\\{64\\}