start_unix.go 2.0 KB

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