Skip to content

Commit

Permalink
compat api: use network mode bridge as default
Browse files Browse the repository at this point in the history
For better docker compatibility we should use the bridge network mode as
default for rootless. This was already done previously but commit
5358184 introduced this regression in v4.0.

Since the apiv2 test are only run rootful we cannot catch this problem
in CI.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Apr 13, 2022
1 parent f6ce14b commit 970c8d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
9 changes: 7 additions & 2 deletions cmd/podman/common/create_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,13 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c
}
}

// netMode
nsmode, networks, netOpts, err := specgen.ParseNetworkFlag([]string{string(cc.HostConfig.NetworkMode)})
// special case for NetworkMode, the podman default is slirp4netns for
// rootless but for better docker compat we want bridge.
netmode := string(cc.HostConfig.NetworkMode)
if netmode == "" || netmode == "default" {
netmode = "bridge"
}
nsmode, networks, netOpts, err := specgen.ParseNetworkFlag([]string{netmode})
if err != nil {
return nil, nil, err
}
Expand Down
13 changes: 2 additions & 11 deletions test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,11 @@ t GET containers/$cid/json 200 \
t POST containers/create Image=$IMAGE Entrypoint='["top"]' 201 \
.Id~[0-9a-f]\\{64\\}
cid_top=$(jq -r '.Id' <<<"$output")
# .Network is N/A when rootless
network_expect=
if root; then
network_expect='.NetworkSettings.Networks.podman.NetworkID=podman'
fi
t GET containers/${cid_top}/json 200 \
.Config.Entrypoint[0]="top" \
.Config.Cmd='[]' \
.Path="top" \
$network_expect
.NetworkSettings.Networks.podman.NetworkID=podman
t POST containers/${cid_top}/start 204
# make sure the container is running
t GET containers/${cid_top}/json 200 \
Expand Down Expand Up @@ -372,15 +367,11 @@ t GET containers/$cid/json 200 \
t DELETE containers/$cid?v=true 204

# Test Compat Create with default network mode (#10569)
networkmode=slirp4netns
if root; then
networkmode=bridge
fi
t POST containers/create Image=$IMAGE HostConfig='{"NetworkMode":"default"}' 201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
t GET containers/$cid/json 200 \
.HostConfig.NetworkMode="$networkmode"
.HostConfig.NetworkMode="bridge"

t DELETE containers/$cid?v=true 204

Expand Down

0 comments on commit 970c8d4

Please sign in to comment.