|
@@ -364,10 +364,15 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConf
|
|
|
|
|
|
// Set default cgroup namespace mode, if unset for container
|
|
|
if hostConfig.CgroupnsMode.IsEmpty() {
|
|
|
- if hostConfig.Privileged {
|
|
|
+ // for cgroup v2: unshare cgroupns even for privileged containers
|
|
|
+ // https://github.com/containers/libpod/pull/4374#issuecomment-549776387
|
|
|
+ if hostConfig.Privileged && !cgroups.IsCgroup2UnifiedMode() {
|
|
|
hostConfig.CgroupnsMode = containertypes.CgroupnsMode("host")
|
|
|
} else {
|
|
|
- m := config.DefaultCgroupNamespaceMode
|
|
|
+ m := "host"
|
|
|
+ if cgroups.IsCgroup2UnifiedMode() {
|
|
|
+ m = "private"
|
|
|
+ }
|
|
|
if daemon.configStore != nil {
|
|
|
m = daemon.configStore.CgroupNamespaceMode
|
|
|
}
|
|
@@ -708,8 +713,8 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.
|
|
|
warnings = append(warnings, "Your kernel does not support cgroup namespaces. Cgroup namespace setting discarded.")
|
|
|
}
|
|
|
|
|
|
- if hostConfig.Privileged {
|
|
|
- return warnings, fmt.Errorf("privileged mode is incompatible with private cgroup namespaces. You must run the container in the host cgroup namespace when running privileged mode")
|
|
|
+ if hostConfig.Privileged && !cgroups.IsCgroup2UnifiedMode() {
|
|
|
+ return warnings, fmt.Errorf("privileged mode is incompatible with private cgroup namespaces on cgroup v1 host. You must run the container in the host cgroup namespace when running privileged mode")
|
|
|
}
|
|
|
}
|
|
|
|