Skip to content

Commit

Permalink
APIv2 compatibility rootless network fix
Browse files Browse the repository at this point in the history
when using the compatibility mode as rootless, containers that were created were not setting their host names correctly due to the netmode not being set.

Fixes: containers#7934

Signed-off-by: baude <[email protected]>
  • Loading branch information
baude authored and mheon committed Oct 14, 2020
1 parent 4ccc231 commit b87cdfa
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/api/handlers/compat/containers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"github.com/containers/podman/v2/pkg/api/handlers"
"github.com/containers/podman/v2/pkg/api/handlers/utils"
"github.com/containers/podman/v2/pkg/namespaces"
"github.com/containers/podman/v2/pkg/rootless"
"github.com/containers/podman/v2/pkg/signal"
createconfig "github.com/containers/podman/v2/pkg/spec"
"github.com/containers/podman/v2/pkg/specgen"
"github.com/containers/storage"
"github.com/gorilla/schema"
"github.com/pkg/errors"
Expand Down Expand Up @@ -134,6 +136,11 @@ func makeCreateConfig(ctx context.Context, containerConfig *config.Config, input
Sysctl: input.HostConfig.Sysctls,
}

var netmode namespaces.NetworkMode
if rootless.IsRootless() {
netmode = namespaces.NetworkMode(specgen.Slirp)
}

network := createconfig.NetworkConfig{
DNSOpt: input.HostConfig.DNSOptions,
DNSSearch: input.HostConfig.DNSSearch,
Expand All @@ -144,7 +151,7 @@ func makeCreateConfig(ctx context.Context, containerConfig *config.Config, input
IPAddress: "",
LinkLocalIP: nil, // docker-only
MacAddress: input.MacAddress,
// NetMode: nil,
NetMode: netmode,
Network: input.HostConfig.NetworkMode.NetworkName(),
NetworkAlias: nil, // docker-only now
PortBindings: input.HostConfig.PortBindings,
Expand Down

0 comments on commit b87cdfa

Please sign in to comment.