Skip to content

Commit

Permalink
Set network ID if available during container inspect. Fixes container…
Browse files Browse the repository at this point in the history
…s#24910

Signed-off-by: Florian Apolloner <[email protected]>
  • Loading branch information
apollo13 committed Jan 6, 2025
1 parent d3cd509 commit 11d8aa1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion contrib/cirrus/setup_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ case "$TEST_FLAVOR" in
;;
compose_v2)
showrun dnf -y remove docker-compose
showrun curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
showrun curl -SL https://github.com/docker/compose/releases/download/v2.31.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
showrun chmod +x /usr/local/bin/docker-compose
;& # Continue with next item
apiv2)
Expand Down
14 changes: 12 additions & 2 deletions libpod/networking_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,13 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
if len(networks) > 0 {
settings.Networks = make(map[string]*define.InspectAdditionalNetwork, len(networks))
for net, opts := range networks {
netID := net
network, err := c.runtime.network.NetworkInspect(net)
if err == nil {
netID = network.ID
}
cniNet := new(define.InspectAdditionalNetwork)
cniNet.NetworkID = net
cniNet.NetworkID = netID
cniNet.Aliases = opts.Aliases
settings.Networks[net] = cniNet
}
Expand Down Expand Up @@ -272,9 +277,14 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
settings.Networks = make(map[string]*define.InspectAdditionalNetwork, len(networks))

for name, opts := range networks {
netID := name
network, err := c.runtime.network.NetworkInspect(name)
if err == nil {
netID = network.ID
}
result := netStatus[name]
addedNet := new(define.InspectAdditionalNetwork)
addedNet.NetworkID = name
addedNet.NetworkID = netID
addedNet.Aliases = opts.Aliases
addedNet.InspectBasicNetworkConfig = resultToBasicNetworkConfig(result)

Expand Down
9 changes: 9 additions & 0 deletions test/compose/uptwice_idempotent/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3'
services:
app:
image: alpine
command: [sleep, infinity]
networks:
- net1
networks:
net1:
12 changes: 12 additions & 0 deletions test/compose/uptwice_idempotent/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- bash -*-

CR=$'\r'
NL=$'\n'

output=$(podman_compose up -d 2>&1)

# Horrible output check here but we really want to make sure that there are
# no unexpected warning/errors and the normal messages are send on stderr as
# well so we cannot check for an empty stderr.
expected="Container uptwice_idempotent-app-1 Running${NL}"
is "$output" "$expected" "no container recreation in compose up (#24950)"

0 comments on commit 11d8aa1

Please sign in to comment.