2016-06-07 07:45:21 +00:00
|
|
|
// +build !windows
|
|
|
|
|
2018-02-05 21:05:59 +00:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2016-05-23 21:49:50 +00:00
|
|
|
|
|
|
|
import (
|
2017-09-22 13:52:41 +00:00
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
|
2017-11-30 00:15:20 +00:00
|
|
|
"github.com/containerd/containerd/linux/runctypes"
|
2016-05-23 21:49:50 +00:00
|
|
|
"github.com/docker/docker/container"
|
2018-01-11 19:53:06 +00:00
|
|
|
"github.com/docker/docker/errdefs"
|
2017-07-19 14:20:13 +00:00
|
|
|
"github.com/pkg/errors"
|
2016-05-23 21:49:50 +00:00
|
|
|
)
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
func (daemon *Daemon) getRuntimeScript(container *container.Container) (string, error) {
|
|
|
|
name := container.HostConfig.Runtime
|
|
|
|
rt := daemon.configStore.GetRuntime(name)
|
|
|
|
if rt == nil {
|
2017-11-29 04:09:37 +00:00
|
|
|
return "", errdefs.InvalidParameter(errors.Errorf("no such runtime '%s'", name))
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2016-05-23 21:49:50 +00:00
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
if len(rt.Args) > 0 {
|
|
|
|
// First check that the target exist, as using it in a script won't
|
|
|
|
// give us the right error
|
|
|
|
if _, err := exec.LookPath(rt.Path); err != nil {
|
|
|
|
return "", translateContainerdStartErr(container.Path, container.SetExitCode, err)
|
|
|
|
}
|
|
|
|
return filepath.Join(daemon.configStore.Root, "runtimes", name), nil
|
|
|
|
}
|
|
|
|
return rt.Path, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// getLibcontainerdCreateOptions callers must hold a lock on the container
|
|
|
|
func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Container) (interface{}, error) {
|
2016-06-20 18:21:01 +00:00
|
|
|
// Ensure a runtime has been assigned to this container
|
|
|
|
if container.HostConfig.Runtime == "" {
|
2017-01-12 19:24:30 +00:00
|
|
|
container.HostConfig.Runtime = daemon.configStore.GetDefaultRuntimeName()
|
2017-03-27 17:18:53 +00:00
|
|
|
container.CheckpointTo(daemon.containersReplica)
|
2016-06-20 18:21:01 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
path, err := daemon.getRuntimeScript(container)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-05-23 21:49:50 +00:00
|
|
|
}
|
2017-11-30 00:15:20 +00:00
|
|
|
opts := &runctypes.RuncOptions{
|
2017-09-22 13:52:41 +00:00
|
|
|
Runtime: path,
|
|
|
|
RuntimeRoot: filepath.Join(daemon.configStore.ExecRoot,
|
|
|
|
fmt.Sprintf("runtime-%s", container.HostConfig.Runtime)),
|
|
|
|
}
|
|
|
|
|
2016-08-26 13:33:26 +00:00
|
|
|
if UsingSystemd(daemon.configStore) {
|
2017-09-22 13:52:41 +00:00
|
|
|
opts.SystemdCgroup = true
|
2016-08-26 13:33:26 +00:00
|
|
|
}
|
2016-05-23 21:49:50 +00:00
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
return opts, nil
|
2016-05-23 21:49:50 +00:00
|
|
|
}
|