2016-06-07 03:45:21 -04:00
// +build !windows
2018-02-05 16:05:59 -05:00
package daemon // import "github.com/docker/docker/daemon"
2016-05-23 17:49:50 -04:00
import (
2020-11-09 09:00:32 -05:00
"github.com/containerd/cgroups"
2016-05-23 17:49:50 -04:00
"github.com/docker/docker/container"
2018-01-11 14:53:06 -05:00
"github.com/docker/docker/errdefs"
2017-07-19 10:20:13 -04:00
"github.com/pkg/errors"
2020-07-07 16:33:46 -04:00
"github.com/sirupsen/logrus"
2016-05-23 17:49:50 -04:00
)
2017-09-22 09:52:41 -04:00
// getLibcontainerdCreateOptions callers must hold a lock on the container
2020-07-07 16:33:46 -04:00
func ( daemon * Daemon ) getLibcontainerdCreateOptions ( container * container . Container ) ( string , interface { } , error ) {
2016-06-20 14:21:01 -04:00
// Ensure a runtime has been assigned to this container
if container . HostConfig . Runtime == "" {
2017-01-12 14:24:30 -05:00
container . HostConfig . Runtime = daemon . configStore . GetDefaultRuntimeName ( )
2017-03-27 13:18:53 -04:00
container . CheckpointTo ( daemon . containersReplica )
2016-06-20 14:21:01 -04:00
}
2020-07-07 16:33:46 -04:00
rt := daemon . configStore . GetRuntime ( container . HostConfig . Runtime )
if rt . Shim == nil {
p , err := daemon . rewriteRuntimePath ( container . HostConfig . Runtime , rt . Path , rt . Args )
if err != nil {
return "" , nil , translateContainerdStartErr ( container . Path , container . SetExitCode , err )
2019-11-05 02:10:19 -05:00
}
2020-07-15 00:58:06 -04:00
rt . Shim = defaultV2ShimConfig ( daemon . configStore , p )
2019-11-05 02:10:19 -05:00
}
2020-07-07 16:33:46 -04:00
if rt . Shim . Binary == linuxShimV1 {
2020-11-09 09:00:32 -05:00
if cgroups . Mode ( ) == cgroups . Unified {
2020-07-07 16:33:46 -04:00
return "" , nil , errdefs . InvalidParameter ( errors . Errorf ( "runtime %q is not supported while cgroups v2 (unified hierarchy) is being used" , container . HostConfig . Runtime ) )
}
logrus . Warnf ( "Configured runtime %q is deprecated and will be removed in the next release" , container . HostConfig . Runtime )
2016-08-26 09:33:26 -04:00
}
2016-05-23 17:49:50 -04:00
2020-07-07 16:33:46 -04:00
return rt . Shim . Binary , rt . Shim . Opts , nil
2016-05-23 17:49:50 -04:00
}