cgroup2: unshare cgroupns by default regardless to API version
| ... | ... |
@@ -10,13 +10,15 @@ type containerRouter struct {
|
| 10 | 10 |
backend Backend |
| 11 | 11 |
decoder httputils.ContainerDecoder |
| 12 | 12 |
routes []router.Route |
| 13 |
+ cgroup2 bool |
|
| 13 | 14 |
} |
| 14 | 15 |
|
| 15 | 16 |
// NewRouter initializes a new container router |
| 16 |
-func NewRouter(b Backend, decoder httputils.ContainerDecoder) router.Router {
|
|
| 17 |
+func NewRouter(b Backend, decoder httputils.ContainerDecoder, cgroup2 bool) router.Router {
|
|
| 17 | 18 |
r := &containerRouter{
|
| 18 | 19 |
backend: b, |
| 19 | 20 |
decoder: decoder, |
| 21 |
+ cgroup2: cgroup2, |
|
| 20 | 22 |
} |
| 21 | 23 |
r.initRoutes() |
| 22 | 24 |
return r |
| ... | ... |
@@ -494,8 +494,8 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo |
| 494 | 494 |
hostConfig.IpcMode = container.IpcMode("shareable")
|
| 495 | 495 |
} |
| 496 | 496 |
} |
| 497 |
- if hostConfig != nil && versions.LessThan(version, "1.41") {
|
|
| 498 |
- // Older clients expect the default to be "host" |
|
| 497 |
+ if hostConfig != nil && versions.LessThan(version, "1.41") && !s.cgroup2 {
|
|
| 498 |
+ // Older clients expect the default to be "host" on cgroup v1 hosts |
|
| 499 | 499 |
if hostConfig.CgroupnsMode.IsEmpty() {
|
| 500 | 500 |
hostConfig.CgroupnsMode = container.CgroupnsMode("host")
|
| 501 | 501 |
} |
| ... | ... |
@@ -477,7 +477,7 @@ func initRouter(opts routerOptions) {
|
| 477 | 477 |
routers := []router.Router{
|
| 478 | 478 |
// we need to add the checkpoint router before the container router or the DELETE gets masked |
| 479 | 479 |
checkpointrouter.NewRouter(opts.daemon, decoder), |
| 480 |
- container.NewRouter(opts.daemon, decoder), |
|
| 480 |
+ container.NewRouter(opts.daemon, decoder, opts.daemon.RawSysInfo(true).CgroupUnified), |
|
| 481 | 481 |
image.NewRouter(opts.daemon.ImageService()), |
| 482 | 482 |
systemrouter.NewRouter(opts.daemon, opts.cluster, opts.buildkit, opts.features), |
| 483 | 483 |
volume.NewRouter(opts.daemon.VolumesService()), |