start_unix.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // +build !windows
  2. package daemon
  3. import (
  4. "fmt"
  5. "os/exec"
  6. "path/filepath"
  7. "github.com/containerd/containerd/linux/runctypes"
  8. "github.com/docker/docker/container"
  9. "github.com/pkg/errors"
  10. )
  11. func (daemon *Daemon) getRuntimeScript(container *container.Container) (string, error) {
  12. name := container.HostConfig.Runtime
  13. rt := daemon.configStore.GetRuntime(name)
  14. if rt == nil {
  15. return "", validationError{errors.Errorf("no such runtime '%s'", name)}
  16. }
  17. if len(rt.Args) > 0 {
  18. // First check that the target exist, as using it in a script won't
  19. // give us the right error
  20. if _, err := exec.LookPath(rt.Path); err != nil {
  21. return "", translateContainerdStartErr(container.Path, container.SetExitCode, err)
  22. }
  23. return filepath.Join(daemon.configStore.Root, "runtimes", name), nil
  24. }
  25. return rt.Path, nil
  26. }
  27. // getLibcontainerdCreateOptions callers must hold a lock on the container
  28. func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Container) (interface{}, error) {
  29. // Ensure a runtime has been assigned to this container
  30. if container.HostConfig.Runtime == "" {
  31. container.HostConfig.Runtime = daemon.configStore.GetDefaultRuntimeName()
  32. container.CheckpointTo(daemon.containersReplica)
  33. }
  34. path, err := daemon.getRuntimeScript(container)
  35. if err != nil {
  36. return nil, err
  37. }
  38. opts := &runctypes.RuncOptions{
  39. Runtime: path,
  40. RuntimeRoot: filepath.Join(daemon.configStore.ExecRoot,
  41. fmt.Sprintf("runtime-%s", container.HostConfig.Runtime)),
  42. }
  43. if UsingSystemd(daemon.configStore) {
  44. opts.SystemdCgroup = true
  45. }
  46. return opts, nil
  47. }