File: requirement_linux.go

package info (click to toggle)
docker.io 20.10.24%2Bdfsg1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates
  • size: 60,824 kB
  • sloc: sh: 5,621; makefile: 593; ansic: 179; python: 162; asm: 7
file content (41 lines) | stat: -rw-r--r-- 1,003 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package requirement // import "github.com/docker/docker/integration/internal/requirement"

import (
	"os"
	"strings"

	"github.com/docker/docker/pkg/parsers/kernel"
	"gotest.tools/v3/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

}