start_unix.go 1.6 KB

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