github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/daemon/start_unix.go (about) 1 // +build !windows 2 3 package daemon // import "github.com/docker/docker/daemon" 4 5 import ( 6 "fmt" 7 "os/exec" 8 "path/filepath" 9 10 "github.com/containerd/containerd/runtime/linux/runctypes" 11 v2runcoptions "github.com/containerd/containerd/runtime/v2/runc/options" 12 "github.com/docker/docker/container" 13 "github.com/docker/docker/errdefs" 14 "github.com/pkg/errors" 15 ) 16 17 func (daemon *Daemon) getRuntimeScript(container *container.Container) (string, error) { 18 name := container.HostConfig.Runtime 19 rt := daemon.configStore.GetRuntime(name) 20 if rt == nil { 21 return "", errdefs.InvalidParameter(errors.Errorf("no such runtime '%s'", name)) 22 } 23 24 if len(rt.Args) > 0 { 25 // First check that the target exist, as using it in a script won't 26 // give us the right error 27 if _, err := exec.LookPath(rt.Path); err != nil { 28 return "", translateContainerdStartErr(container.Path, container.SetExitCode, err) 29 } 30 return filepath.Join(daemon.configStore.Root, "runtimes", name), nil 31 } 32 return rt.Path, nil 33 } 34 35 // getLibcontainerdCreateOptions callers must hold a lock on the container 36 func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Container) (interface{}, error) { 37 // Ensure a runtime has been assigned to this container 38 if container.HostConfig.Runtime == "" { 39 container.HostConfig.Runtime = daemon.configStore.GetDefaultRuntimeName() 40 container.CheckpointTo(daemon.containersReplica) 41 } 42 43 path, err := daemon.getRuntimeScript(container) 44 if err != nil { 45 return nil, err 46 } 47 if daemon.useShimV2() { 48 opts := &v2runcoptions.Options{ 49 BinaryName: path, 50 Root: filepath.Join(daemon.configStore.ExecRoot, 51 fmt.Sprintf("runtime-%s", container.HostConfig.Runtime)), 52 } 53 54 if UsingSystemd(daemon.configStore) { 55 opts.SystemdCgroup = true 56 } 57 58 return opts, nil 59 60 } 61 opts := &runctypes.RuncOptions{ 62 Runtime: path, 63 RuntimeRoot: filepath.Join(daemon.configStore.ExecRoot, 64 fmt.Sprintf("runtime-%s", container.HostConfig.Runtime)), 65 } 66 67 if UsingSystemd(daemon.configStore) { 68 opts.SystemdCgroup = true 69 } 70 71 return opts, nil 72 }