|
@@ -4,11 +4,15 @@ import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
"os"
|
|
|
+ "path/filepath"
|
|
|
"time"
|
|
|
|
|
|
"github.com/containerd/log"
|
|
|
"github.com/docker/docker/daemon/config"
|
|
|
+ "github.com/docker/docker/libcontainerd/supervisor"
|
|
|
"github.com/docker/docker/pkg/system"
|
|
|
+ "github.com/pkg/errors"
|
|
|
+ "github.com/sirupsen/logrus"
|
|
|
"golang.org/x/sys/windows"
|
|
|
)
|
|
|
|
|
@@ -57,6 +61,17 @@ func notifyShutdown(err error) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (cli *DaemonCli) getPlatformContainerdDaemonOpts() ([]supervisor.DaemonOpt, error) {
|
|
|
+ opts := []supervisor.DaemonOpt{
|
|
|
+ // On Windows, it first checks if a containerd binary is found in the same
|
|
|
+ // directory as the dockerd binary. If found, this binary takes precedence
|
|
|
+ // over containerd binaries installed in $PATH.
|
|
|
+ supervisor.WithDetectLocalBinary(),
|
|
|
+ }
|
|
|
+
|
|
|
+ return opts, nil
|
|
|
+}
|
|
|
+
|
|
|
// setupConfigReloadTrap configures a Win32 event to reload the configuration.
|
|
|
func (cli *DaemonCli) setupConfigReloadTrap() {
|
|
|
go func() {
|
|
@@ -89,9 +104,32 @@ func newCgroupParent(config *config.Config) string {
|
|
|
return ""
|
|
|
}
|
|
|
|
|
|
-func (cli *DaemonCli) initContainerd(_ context.Context) (func(time.Duration) error, error) {
|
|
|
- system.InitContainerdRuntime(cli.ContainerdAddr)
|
|
|
- return nil, nil
|
|
|
+func (cli *DaemonCli) initContainerd(ctx context.Context) (func(time.Duration) error, error) {
|
|
|
+ if cli.ContainerdAddr != "" {
|
|
|
+ // use system containerd at the given address.
|
|
|
+ system.InitContainerdRuntime(cli.ContainerdAddr)
|
|
|
+ return nil, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ if cli.DefaultRuntime != config.WindowsV2RuntimeName {
|
|
|
+ return nil, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ logrus.Info("containerd not running, starting managed containerd")
|
|
|
+ opts, err := cli.getContainerdDaemonOpts()
|
|
|
+ if err != nil {
|
|
|
+ return nil, errors.Wrap(err, "failed to generate containerd options")
|
|
|
+ }
|
|
|
+
|
|
|
+ r, err := supervisor.Start(ctx, filepath.Join(cli.Root, "containerd"), filepath.Join(cli.ExecRoot, "containerd"), opts...)
|
|
|
+ if err != nil {
|
|
|
+ return nil, errors.Wrap(err, "failed to start containerd")
|
|
|
+ }
|
|
|
+ cli.ContainerdAddr = r.Address()
|
|
|
+ system.InitContainerdRuntime(r.Address())
|
|
|
+
|
|
|
+ // Try to wait for containerd to shutdown
|
|
|
+ return r.WaitTimeout, nil
|
|
|
}
|
|
|
|
|
|
func validateCPURealtimeOptions(_ *config.Config) error {
|