1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration/internal/requirement/requirement_linux.go
Rob Gulewich 072400fc4b Make cgroup namespaces configurable
This adds both a daemon-wide flag and a container creation property:
- Set the `CgroupnsMode: "host|private"` HostConfig property at
  container creation time to control what cgroup namespace the container
  is created in
- Set the `--default-cgroupns-mode=host|private` daemon flag to control
  what cgroup namespace containers are created in by default
- Set the default if the daemon flag is unset to "host", for backward
  compatibility
- Default to CgroupnsMode: "host" for client versions < 1.40

Signed-off-by: Rob Gulewich <rgulewich@netflix.com>
2019-05-07 10:22:16 -07:00

41 lines
1,000 B
Go

package requirement // import "github.com/docker/docker/integration/internal/requirement"
import (
"os"
"strings"
"github.com/docker/docker/pkg/parsers/kernel"
"gotest.tools/icmd"
)
// CgroupNamespacesEnabled checks if cgroup namespaces are enabled on this host
func CgroupNamespacesEnabled() bool {
if _, err := os.Stat("/proc/self/ns/cgroup"); os.IsNotExist(err) {
return false
}
return true
}
func overlayFSSupported() bool {
result := icmd.RunCommand("/bin/sh", "-c", "cat /proc/filesystems")
if result.Error != nil {
return false
}
return strings.Contains(result.Combined(), "overlay\n")
}
// Overlay2Supported returns true if the current system supports overlay2 as graphdriver
func Overlay2Supported(kernelVersion string) bool {
if !overlayFSSupported() {
return false
}
daemonV, err := kernel.ParseRelease(kernelVersion)
if err != nil {
return false
}
requiredV := kernel.VersionInfo{Kernel: 4}
return kernel.CompareKernelVersion(*daemonV, requiredV) > -1
}