It's "/docker" for cgroupfs and "system.slice" for systemd.
Fix #19140
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
| ... | ... |
@@ -78,7 +78,7 @@ func (config *Config) InstallFlags(cmd *flag.FlagSet, usageFn func(string) strin |
| 78 | 78 |
cmd.BoolVar(&config.Bridge.EnableUserlandProxy, []string{"-userland-proxy"}, true, usageFn("Use userland proxy for loopback traffic"))
|
| 79 | 79 |
cmd.BoolVar(&config.EnableCors, []string{"#api-enable-cors", "#-api-enable-cors"}, false, usageFn("Enable CORS headers in the remote API, this is deprecated by --api-cors-header"))
|
| 80 | 80 |
cmd.StringVar(&config.CorsHeaders, []string{"-api-cors-header"}, "", usageFn("Set CORS headers in the remote API"))
|
| 81 |
- cmd.StringVar(&config.CgroupParent, []string{"-cgroup-parent"}, "/docker", usageFn("Set parent cgroup for all containers"))
|
|
| 81 |
+ cmd.StringVar(&config.CgroupParent, []string{"-cgroup-parent"}, "", usageFn("Set parent cgroup for all containers"))
|
|
| 82 | 82 |
|
| 83 | 83 |
config.attachExperimentalFlags(cmd, usageFn) |
| 84 | 84 |
} |
| ... | ... |
@@ -23,6 +23,7 @@ import ( |
| 23 | 23 |
"github.com/docker/docker/pkg/fileutils" |
| 24 | 24 |
"github.com/docker/docker/pkg/idtools" |
| 25 | 25 |
"github.com/docker/docker/pkg/mount" |
| 26 |
+ "github.com/docker/docker/pkg/parsers" |
|
| 26 | 27 |
"github.com/docker/docker/pkg/stringid" |
| 27 | 28 |
"github.com/docker/docker/runconfig" |
| 28 | 29 |
"github.com/docker/go-units" |
| ... | ... |
@@ -241,6 +242,20 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro |
| 241 | 241 |
} |
| 242 | 242 |
uidMap, gidMap := daemon.GetUIDGIDMaps() |
| 243 | 243 |
|
| 244 |
+ defaultCgroupParent := "/docker" |
|
| 245 |
+ if daemon.configStore.CgroupParent != "" {
|
|
| 246 |
+ defaultCgroupParent = daemon.configStore.CgroupParent |
|
| 247 |
+ } else {
|
|
| 248 |
+ for _, option := range daemon.configStore.ExecOptions {
|
|
| 249 |
+ key, val, err := parsers.ParseKeyValueOpt(option) |
|
| 250 |
+ if err != nil || !strings.EqualFold(key, "native.cgroupdriver") {
|
|
| 251 |
+ continue |
|
| 252 |
+ } |
|
| 253 |
+ if val == "systemd" {
|
|
| 254 |
+ defaultCgroupParent = "system.slice" |
|
| 255 |
+ } |
|
| 256 |
+ } |
|
| 257 |
+ } |
|
| 244 | 258 |
c.Command = &execdriver.Command{
|
| 245 | 259 |
CommonCommand: execdriver.CommonCommand{
|
| 246 | 260 |
ID: c.ID, |
| ... | ... |
@@ -258,7 +273,7 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro |
| 258 | 258 |
AutoCreatedDevices: autoCreatedDevices, |
| 259 | 259 |
CapAdd: c.HostConfig.CapAdd.Slice(), |
| 260 | 260 |
CapDrop: c.HostConfig.CapDrop.Slice(), |
| 261 |
- CgroupParent: daemon.configStore.CgroupParent, |
|
| 261 |
+ CgroupParent: defaultCgroupParent, |
|
| 262 | 262 |
GIDMapping: gidMap, |
| 263 | 263 |
GroupAdd: c.HostConfig.GroupAdd, |
| 264 | 264 |
Ipc: ipc, |
| ... | ... |
@@ -146,14 +146,11 @@ func InitContainer(c *Command) *configs.Config {
|
| 146 | 146 |
// This can be overridden later by driver during mount setup based |
| 147 | 147 |
// on volume options |
| 148 | 148 |
SetRootPropagation(container, mount.RPRIVATE) |
| 149 |
+ container.Cgroups.Parent = c.CgroupParent |
|
| 149 | 150 |
|
| 150 | 151 |
// check to see if we are running in ramdisk to disable pivot root |
| 151 | 152 |
container.NoPivotRoot = os.Getenv("DOCKER_RAMDISK") != ""
|
| 152 | 153 |
|
| 153 |
- // Default parent cgroup is "docker". Override if required. |
|
| 154 |
- if c.CgroupParent != "" {
|
|
| 155 |
- container.Cgroups.Parent = c.CgroupParent |
|
| 156 |
- } |
|
| 157 | 154 |
return container |
| 158 | 155 |
} |
| 159 | 156 |
|
| ... | ... |
@@ -16,7 +16,6 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
"github.com/Sirupsen/logrus" |
| 18 | 18 |
"github.com/docker/docker/daemon/execdriver" |
| 19 |
- "github.com/docker/docker/daemon/execdriver/native/template" |
|
| 20 | 19 |
"github.com/docker/docker/pkg/parsers" |
| 21 | 20 |
"github.com/docker/docker/pkg/pools" |
| 22 | 21 |
"github.com/docker/docker/pkg/reexec" |
| ... | ... |
@@ -90,7 +89,6 @@ func NewDriver(root string, options []string) (*Driver, error) {
|
| 90 | 90 |
case "systemd": |
| 91 | 91 |
if systemd.UseSystemd() {
|
| 92 | 92 |
cgm = libcontainer.SystemdCgroups |
| 93 |
- template.SystemdCgroups = true |
|
| 94 | 93 |
} else {
|
| 95 | 94 |
// warn them that they chose the wrong driver |
| 96 | 95 |
logrus.Warn("You cannot use systemd as native.cgroupdriver, using cgroupfs instead")
|
| ... | ... |
@@ -9,9 +9,6 @@ import ( |
| 9 | 9 |
|
| 10 | 10 |
const defaultMountFlags = syscall.MS_NOEXEC | syscall.MS_NOSUID | syscall.MS_NODEV |
| 11 | 11 |
|
| 12 |
-// SystemdCgroups indicates whether systemd cgroup implemenation is in use or not |
|
| 13 |
-var SystemdCgroups = false |
|
| 14 |
- |
|
| 15 | 12 |
// New returns the docker default configuration for libcontainer |
| 16 | 13 |
func New() *configs.Config {
|
| 17 | 14 |
container := &configs.Config{
|
| ... | ... |
@@ -40,7 +37,7 @@ func New() *configs.Config {
|
| 40 | 40 |
{Type: "NEWUSER"},
|
| 41 | 41 |
}), |
| 42 | 42 |
Cgroups: &configs.Cgroup{
|
| 43 |
- Parent: "/docker", |
|
| 43 |
+ ScopePrefix: "docker", // systemd only |
|
| 44 | 44 |
Resources: &configs.Resources{
|
| 45 | 45 |
AllowAllDevices: false, |
| 46 | 46 |
MemorySwappiness: -1, |
| ... | ... |
@@ -99,10 +96,5 @@ func New() *configs.Config {
|
| 99 | 99 |
container.AppArmorProfile = "docker-default" |
| 100 | 100 |
} |
| 101 | 101 |
|
| 102 |
- if SystemdCgroups {
|
|
| 103 |
- container.Cgroups.Parent = "system.slice" |
|
| 104 |
- container.Cgroups.ScopePrefix = "docker" |
|
| 105 |
- } |
|
| 106 |
- |
|
| 107 | 102 |
return container |
| 108 | 103 |
} |
| ... | ... |
@@ -17,10 +17,10 @@ weight = -1 |
| 17 | 17 |
|
| 18 | 18 |
Options: |
| 19 | 19 |
--api-cors-header="" Set CORS headers in the remote API |
| 20 |
- --authz-plugin=[] Set authorization plugins to load |
|
| 20 |
+ --authz-plugin=[] Set authorization plugins to load |
|
| 21 | 21 |
-b, --bridge="" Attach containers to a network bridge |
| 22 | 22 |
--bip="" Specify network bridge IP |
| 23 |
- --cgroup-parent=/docker Set parent cgroup for all containers |
|
| 23 |
+ --cgroup-parent= Set parent cgroup for all containers |
|
| 24 | 24 |
-D, --debug Enable debug mode |
| 25 | 25 |
--default-gateway="" Container default gateway IPv4 address |
| 26 | 26 |
--default-gateway-v6="" Container default gateway IPv6 address |
| ... | ... |
@@ -647,7 +647,8 @@ set like this: |
| 647 | 647 |
# Default cgroup parent |
| 648 | 648 |
|
| 649 | 649 |
The `--cgroup-parent` option allows you to set the default cgroup parent |
| 650 |
-to use for containers. If this option is not set, it defaults to `/docker`. |
|
| 650 |
+to use for containers. If this option is not set, it defaults to `/docker` for |
|
| 651 |
+fs cgroup driver and `system.slice` for systemd cgroup driver. |
|
| 651 | 652 |
|
| 652 | 653 |
If the cgroup has a leading forward slash (`/`), the cgroup is created |
| 653 | 654 |
under the root cgroup, otherwise the cgroup is created under the daemon |
| ... | ... |
@@ -10,7 +10,7 @@ docker-daemon - Enable daemon mode |
| 10 | 10 |
[**--authz-plugin**[=*[]*]] |
| 11 | 11 |
[**-b**|**--bridge**[=*BRIDGE*]] |
| 12 | 12 |
[**--bip**[=*BIP*]] |
| 13 |
-[**--cgroup-parent**[=*/docker*]] |
|
| 13 |
+[**--cgroup-parent**[=*[]*]] |
|
| 14 | 14 |
[**--cluster-store**[=*[]*]] |
| 15 | 15 |
[**--cluster-advertise**[=*[]*]] |
| 16 | 16 |
[**--cluster-store-opt**[=*map[]*]] |
| ... | ... |
@@ -82,7 +82,7 @@ format. |
| 82 | 82 |
Use the provided CIDR notation address for the dynamically created bridge (docker0); Mutually exclusive of \-b |
| 83 | 83 |
|
| 84 | 84 |
**--cgroup-parent**="" |
| 85 |
- Set parent cgroup for all containers. Default is "/docker". |
|
| 85 |
+ Set parent cgroup for all containers. Default is "/docker" for fs cgroup driver and "system.slice" for systemd cgroup driver. |
|
| 86 | 86 |
|
| 87 | 87 |
**--cluster-store**="" |
| 88 | 88 |
URL of the distributed storage backend |