Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docker compat] Don't overwrite the NetworkMode from "default" to "bridge" if containers.conf specifies a non-default configuration. #17064

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/api/handlers/compat/containers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,17 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
}

// special case for NetworkMode, the podman default is slirp4netns for
// rootless but for better docker compat we want bridge.
// rootless but for better docker compat we want bridge. Do this only if
// the default config in containers.conf wasn't overridden to use another
// value than the default "private" one.
netmode := string(cc.HostConfig.NetworkMode)
configDefaultNetNS := rtc.Containers.NetNS
if netmode == "" || netmode == "default" {
netmode = "bridge"
if configDefaultNetNS == "" || configDefaultNetNS == string(specgen.Default) || configDefaultNetNS == string(specgen.Private) {
mheon marked this conversation as resolved.
Show resolved Hide resolved
netmode = "bridge"
} else {
netmode = configDefaultNetNS
}
}

nsmode, networks, netOpts, err := specgen.ParseNetworkFlag([]string{netmode}, false)
Expand Down
18 changes: 18 additions & 0 deletions test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,24 @@ t GET containers/$cid/json 200 \

t DELETE containers/$cid?v=true 204

# test create with default netns="host"
stop_service
CONTAINERS_CONF=$TESTS_DIR/containers.host-netns.conf start_service

# check that the default docker netns "default" is rewritten to "host"
# when the containers.conf explicitly uses "host"
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="host"

t DELETE containers/$cid?v=true 204

# Restart with the default containers.conf for next tests.
stop_service
start_service

# Test Compat Create with healthcheck, check default values
t POST containers/create Image=$IMAGE Cmd='["top"]' Healthcheck='{"Test":["true"]}' 201 \
.Id~[0-9a-f]\\{64\\}
Expand Down
2 changes: 2 additions & 0 deletions test/apiv2/containers.host-netns.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[containers]
netns="host"