Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
package local // import "github.com/docker/docker/libcontainerd/local"
|
|
|
|
|
|
|
|
// This package contains the legacy in-proc calls in HCS using the v1 schema
|
|
|
|
// for Windows runtime purposes.
|
2017-09-22 13:52:41 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2021-08-24 10:10:50 +00:00
|
|
|
"io"
|
2017-09-22 13:52:41 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/Microsoft/hcsshim"
|
2017-11-03 00:21:18 +00:00
|
|
|
"github.com/containerd/containerd"
|
2017-12-07 19:26:27 +00:00
|
|
|
"github.com/containerd/containerd/cio"
|
2023-04-08 17:30:33 +00:00
|
|
|
cerrdefs "github.com/containerd/containerd/errdefs"
|
2023-09-13 15:41:45 +00:00
|
|
|
"github.com/containerd/log"
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"github.com/docker/docker/errdefs"
|
|
|
|
"github.com/docker/docker/libcontainerd/queue"
|
|
|
|
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
2017-09-22 13:52:41 +00:00
|
|
|
"github.com/docker/docker/pkg/sysinfo"
|
|
|
|
"github.com/docker/docker/pkg/system"
|
|
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"golang.org/x/sys/windows"
|
|
|
|
)
|
|
|
|
|
|
|
|
type process struct {
|
2022-05-10 19:59:00 +00:00
|
|
|
// mu guards the mutable fields of this struct.
|
|
|
|
//
|
|
|
|
// Always lock mu before ctr's mutex to prevent deadlocks.
|
|
|
|
mu sync.Mutex
|
|
|
|
id string // Invariants: immutable
|
|
|
|
ctr *container // Invariants: immutable, ctr != nil
|
|
|
|
hcsProcess hcsshim.Process // Is set to nil on process exit
|
|
|
|
exited *containerd.ExitStatus // Valid iff waitCh is closed
|
|
|
|
waitCh chan struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type task struct {
|
|
|
|
process
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type container struct {
|
2022-05-10 19:59:00 +00:00
|
|
|
mu sync.Mutex
|
2017-09-22 13:52:41 +00:00
|
|
|
|
|
|
|
// The ociSpec is required, as client.Create() needs a spec, but can
|
|
|
|
// be called from the RestartManager context which does not otherwise
|
|
|
|
// have access to the Spec
|
2022-05-10 19:59:00 +00:00
|
|
|
//
|
|
|
|
// A container value with ociSpec == nil represents a container which
|
|
|
|
// has been loaded with (*client).LoadContainer, and is ineligible to
|
|
|
|
// be Start()ed.
|
2017-09-22 13:52:41 +00:00
|
|
|
ociSpec *specs.Spec
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
hcsContainer hcsshim.Container // Is set to nil on container delete
|
|
|
|
isPaused bool
|
2018-08-02 22:09:15 +00:00
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
client *client
|
2018-08-02 22:09:15 +00:00
|
|
|
id string
|
|
|
|
terminateInvoked bool
|
2022-05-10 19:59:00 +00:00
|
|
|
|
|
|
|
// task is a reference to the current task for the container. As a
|
|
|
|
// corollary, when task == nil the container has no current task: the
|
|
|
|
// container was never Start()ed or the task was Delete()d.
|
|
|
|
task *task
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// defaultOwner is a tag passed to HCS to allow it to differentiate between
|
|
|
|
// container creator management stacks. We hard code "docker" in the case
|
|
|
|
// of docker.
|
|
|
|
const defaultOwner = "docker"
|
|
|
|
|
2018-05-23 19:15:21 +00:00
|
|
|
type client struct {
|
2022-05-10 19:59:00 +00:00
|
|
|
stateDir string
|
|
|
|
backend libcontainerdtypes.Backend
|
2023-09-15 11:51:51 +00:00
|
|
|
logger *log.Entry
|
2022-05-10 19:59:00 +00:00
|
|
|
eventQ queue.Queue
|
2018-05-23 19:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewClient creates a new local executor for windows
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
func NewClient(ctx context.Context, cli *containerd.Client, stateDir, ns string, b libcontainerdtypes.Backend) (libcontainerdtypes.Client, error) {
|
2018-05-23 19:15:21 +00:00
|
|
|
c := &client{
|
2022-05-10 19:59:00 +00:00
|
|
|
stateDir: stateDir,
|
|
|
|
backend: b,
|
2023-06-23 00:33:17 +00:00
|
|
|
logger: log.G(ctx).WithField("module", "libcontainerd").WithField("namespace", ns),
|
2018-05-23 19:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2017-11-03 00:21:18 +00:00
|
|
|
func (c *client) Version(ctx context.Context) (containerd.Version, error) {
|
|
|
|
return containerd.Version{}, errors.New("not implemented on Windows")
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// NewContainer is the entrypoint to create a container from a spec.
|
2017-09-22 13:52:41 +00:00
|
|
|
// Table below shows the fields required for HCS JSON calling parameters,
|
|
|
|
// where if not populated, is omitted.
|
|
|
|
// +-----------------+--------------------------------------------+---------------------------------------------------+
|
|
|
|
// | | Isolation=Process | Isolation=Hyper-V |
|
|
|
|
// +-----------------+--------------------------------------------+---------------------------------------------------+
|
|
|
|
// | VolumePath | \\?\\Volume{GUIDa} | |
|
2018-02-09 18:08:47 +00:00
|
|
|
// | LayerFolderPath | %root%\windowsfilter\containerID | |
|
2017-09-22 13:52:41 +00:00
|
|
|
// | Layers[] | ID=GUIDb;Path=%root%\windowsfilter\layerID | ID=GUIDb;Path=%root%\windowsfilter\layerID |
|
|
|
|
// | HvRuntime | | ImagePath=%root%\BaseLayerID\UtilityVM |
|
|
|
|
// +-----------------+--------------------------------------------+---------------------------------------------------+
|
|
|
|
//
|
|
|
|
// Isolation=Process example:
|
|
|
|
//
|
2022-07-08 16:27:07 +00:00
|
|
|
// {
|
|
|
|
// "SystemType": "Container",
|
|
|
|
// "Name": "5e0055c814a6005b8e57ac59f9a522066e0af12b48b3c26a9416e23907698776",
|
|
|
|
// "Owner": "docker",
|
|
|
|
// "VolumePath": "\\\\\\\\?\\\\Volume{66d1ef4c-7a00-11e6-8948-00155ddbef9d}",
|
|
|
|
// "IgnoreFlushesDuringBoot": true,
|
|
|
|
// "LayerFolderPath": "C:\\\\control\\\\windowsfilter\\\\5e0055c814a6005b8e57ac59f9a522066e0af12b48b3c26a9416e23907698776",
|
|
|
|
// "Layers": [{
|
|
|
|
// "ID": "18955d65-d45a-557b-bf1c-49d6dfefc526",
|
|
|
|
// "Path": "C:\\\\control\\\\windowsfilter\\\\65bf96e5760a09edf1790cb229e2dfb2dbd0fcdc0bf7451bae099106bfbfea0c"
|
|
|
|
// }],
|
|
|
|
// "HostName": "5e0055c814a6",
|
|
|
|
// "MappedDirectories": [],
|
|
|
|
// "HvPartition": false,
|
|
|
|
// "EndpointList": ["eef2649d-bb17-4d53-9937-295a8efe6f2c"],
|
|
|
|
// }
|
2017-09-22 13:52:41 +00:00
|
|
|
//
|
|
|
|
// Isolation=Hyper-V example:
|
|
|
|
//
|
2022-07-08 16:27:07 +00:00
|
|
|
// {
|
|
|
|
// "SystemType": "Container",
|
|
|
|
// "Name": "475c2c58933b72687a88a441e7e0ca4bd72d76413c5f9d5031fee83b98f6045d",
|
|
|
|
// "Owner": "docker",
|
|
|
|
// "IgnoreFlushesDuringBoot": true,
|
|
|
|
// "Layers": [{
|
|
|
|
// "ID": "18955d65-d45a-557b-bf1c-49d6dfefc526",
|
|
|
|
// "Path": "C:\\\\control\\\\windowsfilter\\\\65bf96e5760a09edf1790cb229e2dfb2dbd0fcdc0bf7451bae099106bfbfea0c"
|
|
|
|
// }],
|
|
|
|
// "HostName": "475c2c58933b",
|
|
|
|
// "MappedDirectories": [],
|
|
|
|
// "HvPartition": true,
|
|
|
|
// "EndpointList": ["e1bb1e61-d56f-405e-b75d-fd520cefa0cb"],
|
|
|
|
// "DNSSearchList": "a.com,b.com,c.com",
|
|
|
|
// "HvRuntime": {
|
|
|
|
// "ImagePath": "C:\\\\control\\\\windowsfilter\\\\65bf96e5760a09edf1790cb229e2dfb2dbd0fcdc0bf7451bae099106bfbfea0c\\\\UtilityVM"
|
|
|
|
// },
|
|
|
|
// }
|
2022-05-10 19:59:00 +00:00
|
|
|
func (c *client) NewContainer(_ context.Context, id string, spec *specs.Spec, shim string, runtimeOptions interface{}, opts ...containerd.NewContainerOpts) (libcontainerdtypes.Container, error) {
|
2019-02-12 20:19:50 +00:00
|
|
|
var err error
|
2021-03-19 10:56:41 +00:00
|
|
|
if spec.Linux != nil {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, errors.New("linux containers are not supported on this platform")
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
ctr, err := c.createWindows(id, spec, runtimeOptions)
|
2019-02-12 20:19:50 +00:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
c.eventQ.Append(id, func() {
|
|
|
|
ei := libcontainerdtypes.EventInfo{
|
|
|
|
ContainerID: id,
|
|
|
|
}
|
2023-07-30 15:18:56 +00:00
|
|
|
c.logger.WithFields(log.Fields{
|
2019-02-12 20:19:50 +00:00
|
|
|
"container": id,
|
|
|
|
"event": libcontainerdtypes.EventCreate,
|
|
|
|
}).Info("sending event")
|
|
|
|
err := c.backend.ProcessEvent(id, libcontainerdtypes.EventCreate, ei)
|
|
|
|
if err != nil {
|
2023-07-30 15:18:56 +00:00
|
|
|
c.logger.WithError(err).WithFields(log.Fields{
|
2019-02-12 20:19:50 +00:00
|
|
|
"container": id,
|
|
|
|
"event": libcontainerdtypes.EventCreate,
|
|
|
|
}).Error("failed to process event")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
return ctr, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
func (c *client) createWindows(id string, spec *specs.Spec, runtimeOptions interface{}) (*container, error) {
|
2017-09-22 13:52:41 +00:00
|
|
|
logger := c.logger.WithField("container", id)
|
|
|
|
configuration := &hcsshim.ContainerConfig{
|
2018-07-04 18:11:49 +00:00
|
|
|
SystemType: "Container",
|
|
|
|
Name: id,
|
|
|
|
Owner: defaultOwner,
|
2017-09-22 13:52:41 +00:00
|
|
|
IgnoreFlushesDuringBoot: spec.Windows.IgnoreFlushesDuringBoot,
|
|
|
|
HostName: spec.Hostname,
|
|
|
|
HvPartition: false,
|
|
|
|
}
|
|
|
|
|
2018-06-16 07:01:35 +00:00
|
|
|
c.extractResourcesFromSpec(spec, configuration)
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
if spec.Windows.Resources != nil {
|
|
|
|
if spec.Windows.Resources.Storage != nil {
|
|
|
|
if spec.Windows.Resources.Storage.Bps != nil {
|
|
|
|
configuration.StorageBandwidthMaximum = *spec.Windows.Resources.Storage.Bps
|
|
|
|
}
|
|
|
|
if spec.Windows.Resources.Storage.Iops != nil {
|
|
|
|
configuration.StorageIOPSMaximum = *spec.Windows.Resources.Storage.Iops
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if spec.Windows.HyperV != nil {
|
|
|
|
configuration.HvPartition = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if spec.Windows.Network != nil {
|
|
|
|
configuration.EndpointList = spec.Windows.Network.EndpointList
|
|
|
|
configuration.AllowUnqualifiedDNSQuery = spec.Windows.Network.AllowUnqualifiedDNSQuery
|
|
|
|
if spec.Windows.Network.DNSSearchList != nil {
|
|
|
|
configuration.DNSSearchList = strings.Join(spec.Windows.Network.DNSSearchList, ",")
|
|
|
|
}
|
|
|
|
configuration.NetworkSharedContainerName = spec.Windows.Network.NetworkSharedContainerName
|
|
|
|
}
|
|
|
|
|
|
|
|
if cs, ok := spec.Windows.CredentialSpec.(string); ok {
|
|
|
|
configuration.Credentials = cs
|
|
|
|
}
|
|
|
|
|
|
|
|
// We must have least two layers in the spec, the bottom one being a
|
|
|
|
// base image, the top one being the RW layer.
|
|
|
|
if spec.Windows.LayerFolders == nil || len(spec.Windows.LayerFolders) < 2 {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, fmt.Errorf("OCI spec is invalid - at least two LayerFolders must be supplied to the runtime")
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Strip off the top-most layer as that's passed in separately to HCS
|
|
|
|
configuration.LayerFolderPath = spec.Windows.LayerFolders[len(spec.Windows.LayerFolders)-1]
|
|
|
|
layerFolders := spec.Windows.LayerFolders[:len(spec.Windows.LayerFolders)-1]
|
|
|
|
|
|
|
|
if configuration.HvPartition {
|
|
|
|
// We don't currently support setting the utility VM image explicitly.
|
2019-09-25 17:51:18 +00:00
|
|
|
// TODO circa RS5, this may be re-locatable.
|
2017-09-22 13:52:41 +00:00
|
|
|
if spec.Windows.HyperV.UtilityVMPath != "" {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, errors.New("runtime does not support an explicit utility VM path for Hyper-V containers")
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find the upper-most utility VM image.
|
|
|
|
var uvmImagePath string
|
|
|
|
for _, path := range layerFolders {
|
|
|
|
fullPath := filepath.Join(path, "UtilityVM")
|
|
|
|
_, err := os.Stat(fullPath)
|
|
|
|
if err == nil {
|
|
|
|
uvmImagePath = fullPath
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if !os.IsNotExist(err) {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if uvmImagePath == "" {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, errors.New("utility VM image could not be found")
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
configuration.HvRuntime = &hcsshim.HvRuntime{ImagePath: uvmImagePath}
|
|
|
|
|
|
|
|
if spec.Root.Path != "" {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, errors.New("OCI spec is invalid - Root.Path must be omitted for a Hyper-V container")
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const volumeGUIDRegex = `^\\\\\?\\(Volume)\{{0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}\}\\$`
|
|
|
|
if _, err := regexp.MatchString(volumeGUIDRegex, spec.Root.Path); err != nil {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, fmt.Errorf(`OCI spec is invalid - Root.Path '%s' must be a volume GUID path in the format '\\?\Volume{GUID}\'`, spec.Root.Path)
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
// HCS API requires the trailing backslash to be removed
|
|
|
|
configuration.VolumePath = spec.Root.Path[:len(spec.Root.Path)-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
if spec.Root.Readonly {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, errors.New(`OCI spec is invalid - Root.Readonly must not be set on Windows`)
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, layerPath := range layerFolders {
|
|
|
|
_, filename := filepath.Split(layerPath)
|
|
|
|
g, err := hcsshim.NameToGuid(filename)
|
|
|
|
if err != nil {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
configuration.Layers = append(configuration.Layers, hcsshim.Layer{
|
|
|
|
ID: g.ToString(),
|
|
|
|
Path: layerPath,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the mounts (volumes, bind mounts etc) to the structure
|
|
|
|
var mds []hcsshim.MappedDir
|
|
|
|
var mps []hcsshim.MappedPipe
|
|
|
|
for _, mount := range spec.Mounts {
|
|
|
|
const pipePrefix = `\\.\pipe\`
|
|
|
|
if mount.Type != "" {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, fmt.Errorf("OCI spec is invalid - Mount.Type '%s' must not be set", mount.Type)
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
if strings.HasPrefix(mount.Destination, pipePrefix) {
|
|
|
|
mp := hcsshim.MappedPipe{
|
|
|
|
HostPath: mount.Source,
|
|
|
|
ContainerPipeName: mount.Destination[len(pipePrefix):],
|
|
|
|
}
|
|
|
|
mps = append(mps, mp)
|
|
|
|
} else {
|
|
|
|
md := hcsshim.MappedDir{
|
|
|
|
HostPath: mount.Source,
|
|
|
|
ContainerPath: mount.Destination,
|
|
|
|
ReadOnly: false,
|
|
|
|
}
|
|
|
|
for _, o := range mount.Options {
|
|
|
|
if strings.ToLower(o) == "ro" {
|
|
|
|
md.ReadOnly = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mds = append(mds, md)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
configuration.MappedDirectories = mds
|
|
|
|
configuration.MappedPipes = mps
|
|
|
|
|
2018-07-16 22:19:11 +00:00
|
|
|
if len(spec.Windows.Devices) > 0 {
|
|
|
|
// Add any device assignments
|
|
|
|
if configuration.HvPartition {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, errors.New("device assignment is not supported for HyperV containers")
|
2018-07-16 22:19:11 +00:00
|
|
|
}
|
|
|
|
for _, d := range spec.Windows.Devices {
|
2022-03-13 06:01:28 +00:00
|
|
|
// Per https://github.com/microsoft/hcsshim/blob/v0.9.2/internal/uvm/virtual_device.go#L17-L18,
|
2022-03-13 09:00:22 +00:00
|
|
|
// these represent an Interface Class GUID.
|
|
|
|
if d.IDType != "class" && d.IDType != "vpci-class-guid" {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, errors.Errorf("device assignment of type '%s' is not supported", d.IDType)
|
2022-03-13 06:01:28 +00:00
|
|
|
}
|
2018-07-16 22:19:11 +00:00
|
|
|
configuration.AssignedDevices = append(configuration.AssignedDevices, hcsshim.AssignedDevice{InterfaceClassGUID: d.ID})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
hcsContainer, err := hcsshim.CreateContainer(id, configuration)
|
|
|
|
if err != nil {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Construct a container object for calling start on it.
|
|
|
|
ctr := &container{
|
2022-05-10 19:59:00 +00:00
|
|
|
client: c,
|
2017-09-22 13:52:41 +00:00
|
|
|
id: id,
|
|
|
|
ociSpec: spec,
|
|
|
|
hcsContainer: hcsContainer,
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Debug("starting container")
|
2022-05-10 19:59:00 +00:00
|
|
|
if err := ctr.hcsContainer.Start(); err != nil {
|
|
|
|
logger.WithError(err).Error("failed to start container")
|
|
|
|
ctr.mu.Lock()
|
|
|
|
if err := ctr.terminateContainer(); err != nil {
|
|
|
|
logger.WithError(err).Error("failed to cleanup after a failed Start")
|
2017-09-22 13:52:41 +00:00
|
|
|
} else {
|
2022-05-10 19:59:00 +00:00
|
|
|
logger.Debug("cleaned up after failed Start by calling Terminate")
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
ctr.mu.Unlock()
|
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
logger.Debug("createWindows() completed successfully")
|
2022-05-10 19:59:00 +00:00
|
|
|
return ctr, nil
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2018-06-16 07:01:35 +00:00
|
|
|
func (c *client) extractResourcesFromSpec(spec *specs.Spec, configuration *hcsshim.ContainerConfig) {
|
|
|
|
if spec.Windows.Resources != nil {
|
|
|
|
if spec.Windows.Resources.CPU != nil {
|
|
|
|
if spec.Windows.Resources.CPU.Count != nil {
|
|
|
|
// This check is being done here rather than in adaptContainerSettings
|
|
|
|
// because we don't want to update the HostConfig in case this container
|
|
|
|
// is moved to a host with more CPUs than this one.
|
|
|
|
cpuCount := *spec.Windows.Resources.CPU.Count
|
|
|
|
hostCPUCount := uint64(sysinfo.NumCPU())
|
|
|
|
if cpuCount > hostCPUCount {
|
|
|
|
c.logger.Warnf("Changing requested CPUCount of %d to current number of processors, %d", cpuCount, hostCPUCount)
|
|
|
|
cpuCount = hostCPUCount
|
|
|
|
}
|
|
|
|
configuration.ProcessorCount = uint32(cpuCount)
|
|
|
|
}
|
|
|
|
if spec.Windows.Resources.CPU.Shares != nil {
|
|
|
|
configuration.ProcessorWeight = uint64(*spec.Windows.Resources.CPU.Shares)
|
|
|
|
}
|
|
|
|
if spec.Windows.Resources.CPU.Maximum != nil {
|
|
|
|
configuration.ProcessorMaximum = int64(*spec.Windows.Resources.CPU.Maximum)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if spec.Windows.Resources.Memory != nil {
|
|
|
|
if spec.Windows.Resources.Memory.Limit != nil {
|
|
|
|
configuration.MemoryMaximumInMB = int64(*spec.Windows.Resources.Memory.Limit) / 1024 / 1024
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-14 09:06:46 +00:00
|
|
|
func (ctr *container) Start(_ context.Context, _ string, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (_ libcontainerdtypes.Task, retErr error) {
|
2022-05-10 19:59:00 +00:00
|
|
|
ctr.mu.Lock()
|
|
|
|
defer ctr.mu.Unlock()
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
switch {
|
2022-05-10 19:59:00 +00:00
|
|
|
case ctr.ociSpec == nil:
|
|
|
|
return nil, errors.WithStack(errdefs.NotImplemented(errors.New("a restored container cannot be started")))
|
|
|
|
case ctr.task != nil:
|
2023-04-08 17:30:33 +00:00
|
|
|
return nil, errors.WithStack(errdefs.NotModified(cerrdefs.ErrAlreadyExists))
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
logger := ctr.client.logger.WithField("container", ctr.id)
|
2017-09-22 13:52:41 +00:00
|
|
|
|
|
|
|
// Note we always tell HCS to create stdout as it's required
|
|
|
|
// regardless of '-i' or '-t' options, so that docker can always grab
|
|
|
|
// the output through logs. We also tell HCS to always create stdin,
|
|
|
|
// even if it's not used - it will be closed shortly. Stderr is only
|
|
|
|
// created if it we're not -t.
|
|
|
|
var (
|
|
|
|
emulateConsole bool
|
|
|
|
createStdErrPipe bool
|
|
|
|
)
|
|
|
|
if ctr.ociSpec.Process != nil {
|
|
|
|
emulateConsole = ctr.ociSpec.Process.Terminal
|
2018-02-09 18:08:47 +00:00
|
|
|
createStdErrPipe = !ctr.ociSpec.Process.Terminal
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
createProcessParms := &hcsshim.ProcessConfig{
|
|
|
|
EmulateConsole: emulateConsole,
|
|
|
|
WorkingDirectory: ctr.ociSpec.Process.Cwd,
|
2018-02-09 18:08:47 +00:00
|
|
|
CreateStdInPipe: true,
|
|
|
|
CreateStdOutPipe: true,
|
2017-09-22 13:52:41 +00:00
|
|
|
CreateStdErrPipe: createStdErrPipe,
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctr.ociSpec.Process != nil && ctr.ociSpec.Process.ConsoleSize != nil {
|
|
|
|
createProcessParms.ConsoleSize[0] = uint(ctr.ociSpec.Process.ConsoleSize.Height)
|
|
|
|
createProcessParms.ConsoleSize[1] = uint(ctr.ociSpec.Process.ConsoleSize.Width)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure the environment for the process
|
|
|
|
createProcessParms.Environment = setupEnvironmentVariables(ctr.ociSpec.Process.Env)
|
Windows: (WCOW) Generate OCI spec that remote runtime can escape
Signed-off-by: John Howard <jhoward@microsoft.com>
Also fixes https://github.com/moby/moby/issues/22874
This commit is a pre-requisite to moving moby/moby on Windows to using
Containerd for its runtime.
The reason for this is that the interface between moby and containerd
for the runtime is an OCI spec which must be unambigious.
It is the responsibility of the runtime (runhcs in the case of
containerd on Windows) to ensure that arguments are escaped prior
to calling into HCS and onwards to the Win32 CreateProcess call.
Previously, the builder was always escaping arguments which has
led to several bugs in moby. Because the local runtime in
libcontainerd had context of whether or not arguments were escaped,
it was possible to hack around in daemon/oci_windows.go with
knowledge of the context of the call (from builder or not).
With a remote runtime, this is not possible as there's rightly
no context of the caller passed across in the OCI spec. Put another
way, as I put above, the OCI spec must be unambigious.
The other previous limitation (which leads to various subtle bugs)
is that moby is coded entirely from a Linux-centric point of view.
Unfortunately, Windows != Linux. Windows CreateProcess uses a
command line, not an array of arguments. And it has very specific
rules about how to escape a command line. Some interesting reading
links about this are:
https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
https://stackoverflow.com/questions/31838469/how-do-i-convert-argv-to-lpcommandline-parameter-of-createprocess
https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments?view=vs-2017
For this reason, the OCI spec has recently been updated to cater
for more natural syntax by including a CommandLine option in
Process.
What does this commit do?
Primary objective is to ensure that the built OCI spec is unambigious.
It changes the builder so that `ArgsEscaped` as commited in a
layer is only controlled by the use of CMD or ENTRYPOINT.
Subsequently, when calling in to create a container from the builder,
if follows a different path to both `docker run` and `docker create`
using the added `ContainerCreateIgnoreImagesArgsEscaped`. This allows
a RUN from the builder to control how to escape in the OCI spec.
It changes the builder so that when shell form is used for RUN,
CMD or ENTRYPOINT, it builds (for WCOW) a more natural command line
using the original as put by the user in the dockerfile, not
the parsed version as a set of args which loses fidelity.
This command line is put into args[0] and `ArgsEscaped` is set
to true for CMD or ENTRYPOINT. A RUN statement does not commit
`ArgsEscaped` to the commited layer regardless or whether shell
or exec form were used.
2019-01-18 00:03:29 +00:00
|
|
|
|
|
|
|
// Configure the CommandLine/CommandArgs
|
2021-03-19 14:03:22 +00:00
|
|
|
setCommandLineAndArgs(ctr.ociSpec.Process, createProcessParms)
|
|
|
|
logger.Debugf("start commandLine: %s", createProcessParms.CommandLine)
|
Windows: (WCOW) Generate OCI spec that remote runtime can escape
Signed-off-by: John Howard <jhoward@microsoft.com>
Also fixes https://github.com/moby/moby/issues/22874
This commit is a pre-requisite to moving moby/moby on Windows to using
Containerd for its runtime.
The reason for this is that the interface between moby and containerd
for the runtime is an OCI spec which must be unambigious.
It is the responsibility of the runtime (runhcs in the case of
containerd on Windows) to ensure that arguments are escaped prior
to calling into HCS and onwards to the Win32 CreateProcess call.
Previously, the builder was always escaping arguments which has
led to several bugs in moby. Because the local runtime in
libcontainerd had context of whether or not arguments were escaped,
it was possible to hack around in daemon/oci_windows.go with
knowledge of the context of the call (from builder or not).
With a remote runtime, this is not possible as there's rightly
no context of the caller passed across in the OCI spec. Put another
way, as I put above, the OCI spec must be unambigious.
The other previous limitation (which leads to various subtle bugs)
is that moby is coded entirely from a Linux-centric point of view.
Unfortunately, Windows != Linux. Windows CreateProcess uses a
command line, not an array of arguments. And it has very specific
rules about how to escape a command line. Some interesting reading
links about this are:
https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
https://stackoverflow.com/questions/31838469/how-do-i-convert-argv-to-lpcommandline-parameter-of-createprocess
https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments?view=vs-2017
For this reason, the OCI spec has recently been updated to cater
for more natural syntax by including a CommandLine option in
Process.
What does this commit do?
Primary objective is to ensure that the built OCI spec is unambigious.
It changes the builder so that `ArgsEscaped` as commited in a
layer is only controlled by the use of CMD or ENTRYPOINT.
Subsequently, when calling in to create a container from the builder,
if follows a different path to both `docker run` and `docker create`
using the added `ContainerCreateIgnoreImagesArgsEscaped`. This allows
a RUN from the builder to control how to escape in the OCI spec.
It changes the builder so that when shell form is used for RUN,
CMD or ENTRYPOINT, it builds (for WCOW) a more natural command line
using the original as put by the user in the dockerfile, not
the parsed version as a set of args which loses fidelity.
This command line is put into args[0] and `ArgsEscaped` is set
to true for CMD or ENTRYPOINT. A RUN statement does not commit
`ArgsEscaped` to the commited layer regardless or whether shell
or exec form were used.
2019-01-18 00:03:29 +00:00
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
createProcessParms.User = ctr.ociSpec.Process.User.Username
|
|
|
|
|
|
|
|
// Start the command running in the container.
|
|
|
|
newProcess, err := ctr.hcsContainer.CreateProcess(createProcessParms)
|
|
|
|
if err != nil {
|
|
|
|
logger.WithError(err).Error("CreateProcess() failed")
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2019-02-12 20:19:50 +00:00
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
defer func() {
|
2023-09-14 09:06:46 +00:00
|
|
|
if retErr != nil {
|
2017-09-22 13:52:41 +00:00
|
|
|
if err := newProcess.Kill(); err != nil {
|
|
|
|
logger.WithError(err).Error("failed to kill process")
|
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
if err := newProcess.Wait(); err != nil {
|
|
|
|
logger.WithError(err).Error("failed to wait for process")
|
|
|
|
}
|
|
|
|
if err := newProcess.Close(); err != nil {
|
|
|
|
logger.WithError(err).Error("failed to clean process resources")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}()
|
2019-02-12 20:19:50 +00:00
|
|
|
|
2023-09-14 09:07:02 +00:00
|
|
|
pid := newProcess.Pid()
|
|
|
|
logger.WithField("pid", pid).Debug("init process started")
|
2019-02-12 20:19:50 +00:00
|
|
|
|
2023-09-14 09:10:40 +00:00
|
|
|
dio, err := newIOFromProcess(newProcess, ctr.ociSpec.Process.Terminal)
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.WithError(err).Error("failed to get stdio pipes")
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2017-12-07 19:26:27 +00:00
|
|
|
_, err = attachStdio(dio)
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
2019-02-12 20:19:50 +00:00
|
|
|
logger.WithError(err).Error("failed to attach stdio")
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2023-09-14 09:07:02 +00:00
|
|
|
t := &task{process{
|
|
|
|
id: ctr.id,
|
|
|
|
ctr: ctr,
|
|
|
|
hcsProcess: newProcess,
|
|
|
|
waitCh: make(chan struct{}),
|
|
|
|
}}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// All fallible operations have succeeded so it is now safe to set the
|
|
|
|
// container's current task.
|
|
|
|
ctr.task = t
|
|
|
|
|
2023-09-14 09:07:02 +00:00
|
|
|
// Spin up a goroutine to notify the backend and clean up resources when
|
|
|
|
// the task exits. Defer until after the start event is sent so that the
|
|
|
|
// exit event is not sent out-of-order.
|
|
|
|
defer func() { go t.reap() }()
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
// Generate the associated event
|
2022-05-10 19:59:00 +00:00
|
|
|
ctr.client.eventQ.Append(ctr.id, func() {
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
ei := libcontainerdtypes.EventInfo{
|
2022-05-10 19:59:00 +00:00
|
|
|
ContainerID: ctr.id,
|
2023-01-30 18:26:26 +00:00
|
|
|
ProcessID: t.id,
|
2023-09-14 09:07:02 +00:00
|
|
|
Pid: uint32(pid),
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2023-07-30 15:18:56 +00:00
|
|
|
ctr.client.logger.WithFields(log.Fields{
|
2017-09-22 13:52:41 +00:00
|
|
|
"container": ctr.id,
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"event": libcontainerdtypes.EventStart,
|
2017-09-22 13:52:41 +00:00
|
|
|
"event-info": ei,
|
|
|
|
}).Info("sending event")
|
2022-05-10 19:59:00 +00:00
|
|
|
err := ctr.client.backend.ProcessEvent(ei.ContainerID, libcontainerdtypes.EventStart, ei)
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
2023-07-30 15:18:56 +00:00
|
|
|
ctr.client.logger.WithError(err).WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": ei.ContainerID,
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"event": libcontainerdtypes.EventStart,
|
2017-09-22 13:52:41 +00:00
|
|
|
"event-info": ei,
|
|
|
|
}).Error("failed to process event")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
logger.Debug("start() completed")
|
2022-05-10 19:59:00 +00:00
|
|
|
return t, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctr *container) Task(context.Context) (libcontainerdtypes.Task, error) {
|
|
|
|
ctr.mu.Lock()
|
|
|
|
defer ctr.mu.Unlock()
|
|
|
|
if ctr.task == nil {
|
2023-04-08 17:30:33 +00:00
|
|
|
return nil, errdefs.NotFound(cerrdefs.ErrNotFound)
|
2022-05-10 19:59:00 +00:00
|
|
|
}
|
|
|
|
return ctr.task, nil
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
Windows: (WCOW) Generate OCI spec that remote runtime can escape
Signed-off-by: John Howard <jhoward@microsoft.com>
Also fixes https://github.com/moby/moby/issues/22874
This commit is a pre-requisite to moving moby/moby on Windows to using
Containerd for its runtime.
The reason for this is that the interface between moby and containerd
for the runtime is an OCI spec which must be unambigious.
It is the responsibility of the runtime (runhcs in the case of
containerd on Windows) to ensure that arguments are escaped prior
to calling into HCS and onwards to the Win32 CreateProcess call.
Previously, the builder was always escaping arguments which has
led to several bugs in moby. Because the local runtime in
libcontainerd had context of whether or not arguments were escaped,
it was possible to hack around in daemon/oci_windows.go with
knowledge of the context of the call (from builder or not).
With a remote runtime, this is not possible as there's rightly
no context of the caller passed across in the OCI spec. Put another
way, as I put above, the OCI spec must be unambigious.
The other previous limitation (which leads to various subtle bugs)
is that moby is coded entirely from a Linux-centric point of view.
Unfortunately, Windows != Linux. Windows CreateProcess uses a
command line, not an array of arguments. And it has very specific
rules about how to escape a command line. Some interesting reading
links about this are:
https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
https://stackoverflow.com/questions/31838469/how-do-i-convert-argv-to-lpcommandline-parameter-of-createprocess
https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments?view=vs-2017
For this reason, the OCI spec has recently been updated to cater
for more natural syntax by including a CommandLine option in
Process.
What does this commit do?
Primary objective is to ensure that the built OCI spec is unambigious.
It changes the builder so that `ArgsEscaped` as commited in a
layer is only controlled by the use of CMD or ENTRYPOINT.
Subsequently, when calling in to create a container from the builder,
if follows a different path to both `docker run` and `docker create`
using the added `ContainerCreateIgnoreImagesArgsEscaped`. This allows
a RUN from the builder to control how to escape in the OCI spec.
It changes the builder so that when shell form is used for RUN,
CMD or ENTRYPOINT, it builds (for WCOW) a more natural command line
using the original as put by the user in the dockerfile, not
the parsed version as a set of args which loses fidelity.
This command line is put into args[0] and `ArgsEscaped` is set
to true for CMD or ENTRYPOINT. A RUN statement does not commit
`ArgsEscaped` to the commited layer regardless or whether shell
or exec form were used.
2019-01-18 00:03:29 +00:00
|
|
|
// setCommandLineAndArgs configures the HCS ProcessConfig based on an OCI process spec
|
2021-03-19 14:03:22 +00:00
|
|
|
func setCommandLineAndArgs(process *specs.Process, createProcessParms *hcsshim.ProcessConfig) {
|
|
|
|
if process.CommandLine != "" {
|
|
|
|
createProcessParms.CommandLine = process.CommandLine
|
Windows: (WCOW) Generate OCI spec that remote runtime can escape
Signed-off-by: John Howard <jhoward@microsoft.com>
Also fixes https://github.com/moby/moby/issues/22874
This commit is a pre-requisite to moving moby/moby on Windows to using
Containerd for its runtime.
The reason for this is that the interface between moby and containerd
for the runtime is an OCI spec which must be unambigious.
It is the responsibility of the runtime (runhcs in the case of
containerd on Windows) to ensure that arguments are escaped prior
to calling into HCS and onwards to the Win32 CreateProcess call.
Previously, the builder was always escaping arguments which has
led to several bugs in moby. Because the local runtime in
libcontainerd had context of whether or not arguments were escaped,
it was possible to hack around in daemon/oci_windows.go with
knowledge of the context of the call (from builder or not).
With a remote runtime, this is not possible as there's rightly
no context of the caller passed across in the OCI spec. Put another
way, as I put above, the OCI spec must be unambigious.
The other previous limitation (which leads to various subtle bugs)
is that moby is coded entirely from a Linux-centric point of view.
Unfortunately, Windows != Linux. Windows CreateProcess uses a
command line, not an array of arguments. And it has very specific
rules about how to escape a command line. Some interesting reading
links about this are:
https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
https://stackoverflow.com/questions/31838469/how-do-i-convert-argv-to-lpcommandline-parameter-of-createprocess
https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments?view=vs-2017
For this reason, the OCI spec has recently been updated to cater
for more natural syntax by including a CommandLine option in
Process.
What does this commit do?
Primary objective is to ensure that the built OCI spec is unambigious.
It changes the builder so that `ArgsEscaped` as commited in a
layer is only controlled by the use of CMD or ENTRYPOINT.
Subsequently, when calling in to create a container from the builder,
if follows a different path to both `docker run` and `docker create`
using the added `ContainerCreateIgnoreImagesArgsEscaped`. This allows
a RUN from the builder to control how to escape in the OCI spec.
It changes the builder so that when shell form is used for RUN,
CMD or ENTRYPOINT, it builds (for WCOW) a more natural command line
using the original as put by the user in the dockerfile, not
the parsed version as a set of args which loses fidelity.
This command line is put into args[0] and `ArgsEscaped` is set
to true for CMD or ENTRYPOINT. A RUN statement does not commit
`ArgsEscaped` to the commited layer regardless or whether shell
or exec form were used.
2019-01-18 00:03:29 +00:00
|
|
|
} else {
|
2021-03-19 14:03:22 +00:00
|
|
|
createProcessParms.CommandLine = system.EscapeArgs(process.Args)
|
Windows: (WCOW) Generate OCI spec that remote runtime can escape
Signed-off-by: John Howard <jhoward@microsoft.com>
Also fixes https://github.com/moby/moby/issues/22874
This commit is a pre-requisite to moving moby/moby on Windows to using
Containerd for its runtime.
The reason for this is that the interface between moby and containerd
for the runtime is an OCI spec which must be unambigious.
It is the responsibility of the runtime (runhcs in the case of
containerd on Windows) to ensure that arguments are escaped prior
to calling into HCS and onwards to the Win32 CreateProcess call.
Previously, the builder was always escaping arguments which has
led to several bugs in moby. Because the local runtime in
libcontainerd had context of whether or not arguments were escaped,
it was possible to hack around in daemon/oci_windows.go with
knowledge of the context of the call (from builder or not).
With a remote runtime, this is not possible as there's rightly
no context of the caller passed across in the OCI spec. Put another
way, as I put above, the OCI spec must be unambigious.
The other previous limitation (which leads to various subtle bugs)
is that moby is coded entirely from a Linux-centric point of view.
Unfortunately, Windows != Linux. Windows CreateProcess uses a
command line, not an array of arguments. And it has very specific
rules about how to escape a command line. Some interesting reading
links about this are:
https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
https://stackoverflow.com/questions/31838469/how-do-i-convert-argv-to-lpcommandline-parameter-of-createprocess
https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments?view=vs-2017
For this reason, the OCI spec has recently been updated to cater
for more natural syntax by including a CommandLine option in
Process.
What does this commit do?
Primary objective is to ensure that the built OCI spec is unambigious.
It changes the builder so that `ArgsEscaped` as commited in a
layer is only controlled by the use of CMD or ENTRYPOINT.
Subsequently, when calling in to create a container from the builder,
if follows a different path to both `docker run` and `docker create`
using the added `ContainerCreateIgnoreImagesArgsEscaped`. This allows
a RUN from the builder to control how to escape in the OCI spec.
It changes the builder so that when shell form is used for RUN,
CMD or ENTRYPOINT, it builds (for WCOW) a more natural command line
using the original as put by the user in the dockerfile, not
the parsed version as a set of args which loses fidelity.
This command line is put into args[0] and `ArgsEscaped` is set
to true for CMD or ENTRYPOINT. A RUN statement does not commit
`ArgsEscaped` to the commited layer regardless or whether shell
or exec form were used.
2019-01-18 00:03:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 20:52:14 +00:00
|
|
|
func newIOFromProcess(newProcess hcsshim.Process, terminal bool) (*cio.DirectIO, error) {
|
2017-12-07 19:26:27 +00:00
|
|
|
stdin, stdout, stderr, err := newProcess.Stdio()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-12-07 20:52:14 +00:00
|
|
|
dio := cio.NewDirectIO(createStdInCloser(stdin, newProcess), nil, nil, terminal)
|
|
|
|
|
2017-12-07 19:26:27 +00:00
|
|
|
// Convert io.ReadClosers to io.Readers
|
|
|
|
if stdout != nil {
|
2021-08-24 10:10:50 +00:00
|
|
|
dio.Stdout = io.NopCloser(&autoClosingReader{ReadCloser: stdout})
|
2017-12-07 19:26:27 +00:00
|
|
|
}
|
|
|
|
if stderr != nil {
|
2021-08-24 10:10:50 +00:00
|
|
|
dio.Stderr = io.NopCloser(&autoClosingReader{ReadCloser: stderr})
|
2017-12-07 19:26:27 +00:00
|
|
|
}
|
|
|
|
return dio, nil
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// Exec launches a process in a running container.
|
|
|
|
//
|
|
|
|
// The processID argument is entirely informational. As there is no mechanism
|
|
|
|
// (exposed through the libcontainerd interfaces) to enumerate or reference an
|
|
|
|
// exec'd process by ID, uniqueness is not currently enforced.
|
2023-09-14 09:06:46 +00:00
|
|
|
func (t *task) Exec(ctx context.Context, processID string, spec *specs.Process, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (_ libcontainerdtypes.Process, retErr error) {
|
2022-05-10 19:59:00 +00:00
|
|
|
hcsContainer, err := t.getHCSContainer()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-07-30 15:18:56 +00:00
|
|
|
logger := t.ctr.client.logger.WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": t.ctr.id,
|
2017-09-22 13:52:41 +00:00
|
|
|
"exec": processID,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Note we always tell HCS to
|
|
|
|
// create stdout as it's required regardless of '-i' or '-t' options, so that
|
|
|
|
// docker can always grab the output through logs. We also tell HCS to always
|
|
|
|
// create stdin, even if it's not used - it will be closed shortly. Stderr
|
|
|
|
// is only created if it we're not -t.
|
Windows: (WCOW) Generate OCI spec that remote runtime can escape
Signed-off-by: John Howard <jhoward@microsoft.com>
Also fixes https://github.com/moby/moby/issues/22874
This commit is a pre-requisite to moving moby/moby on Windows to using
Containerd for its runtime.
The reason for this is that the interface between moby and containerd
for the runtime is an OCI spec which must be unambigious.
It is the responsibility of the runtime (runhcs in the case of
containerd on Windows) to ensure that arguments are escaped prior
to calling into HCS and onwards to the Win32 CreateProcess call.
Previously, the builder was always escaping arguments which has
led to several bugs in moby. Because the local runtime in
libcontainerd had context of whether or not arguments were escaped,
it was possible to hack around in daemon/oci_windows.go with
knowledge of the context of the call (from builder or not).
With a remote runtime, this is not possible as there's rightly
no context of the caller passed across in the OCI spec. Put another
way, as I put above, the OCI spec must be unambigious.
The other previous limitation (which leads to various subtle bugs)
is that moby is coded entirely from a Linux-centric point of view.
Unfortunately, Windows != Linux. Windows CreateProcess uses a
command line, not an array of arguments. And it has very specific
rules about how to escape a command line. Some interesting reading
links about this are:
https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
https://stackoverflow.com/questions/31838469/how-do-i-convert-argv-to-lpcommandline-parameter-of-createprocess
https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments?view=vs-2017
For this reason, the OCI spec has recently been updated to cater
for more natural syntax by including a CommandLine option in
Process.
What does this commit do?
Primary objective is to ensure that the built OCI spec is unambigious.
It changes the builder so that `ArgsEscaped` as commited in a
layer is only controlled by the use of CMD or ENTRYPOINT.
Subsequently, when calling in to create a container from the builder,
if follows a different path to both `docker run` and `docker create`
using the added `ContainerCreateIgnoreImagesArgsEscaped`. This allows
a RUN from the builder to control how to escape in the OCI spec.
It changes the builder so that when shell form is used for RUN,
CMD or ENTRYPOINT, it builds (for WCOW) a more natural command line
using the original as put by the user in the dockerfile, not
the parsed version as a set of args which loses fidelity.
This command line is put into args[0] and `ArgsEscaped` is set
to true for CMD or ENTRYPOINT. A RUN statement does not commit
`ArgsEscaped` to the commited layer regardless or whether shell
or exec form were used.
2019-01-18 00:03:29 +00:00
|
|
|
createProcessParms := &hcsshim.ProcessConfig{
|
2017-09-22 13:52:41 +00:00
|
|
|
CreateStdInPipe: true,
|
|
|
|
CreateStdOutPipe: true,
|
|
|
|
CreateStdErrPipe: !spec.Terminal,
|
|
|
|
}
|
|
|
|
if spec.Terminal {
|
|
|
|
createProcessParms.EmulateConsole = true
|
|
|
|
if spec.ConsoleSize != nil {
|
|
|
|
createProcessParms.ConsoleSize[0] = uint(spec.ConsoleSize.Height)
|
|
|
|
createProcessParms.ConsoleSize[1] = uint(spec.ConsoleSize.Width)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Take working directory from the process to add if it is defined,
|
|
|
|
// otherwise take from the first process.
|
|
|
|
if spec.Cwd != "" {
|
|
|
|
createProcessParms.WorkingDirectory = spec.Cwd
|
|
|
|
} else {
|
2022-05-10 19:59:00 +00:00
|
|
|
createProcessParms.WorkingDirectory = t.ctr.ociSpec.Process.Cwd
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Configure the environment for the process
|
|
|
|
createProcessParms.Environment = setupEnvironmentVariables(spec.Env)
|
|
|
|
|
Windows: (WCOW) Generate OCI spec that remote runtime can escape
Signed-off-by: John Howard <jhoward@microsoft.com>
Also fixes https://github.com/moby/moby/issues/22874
This commit is a pre-requisite to moving moby/moby on Windows to using
Containerd for its runtime.
The reason for this is that the interface between moby and containerd
for the runtime is an OCI spec which must be unambigious.
It is the responsibility of the runtime (runhcs in the case of
containerd on Windows) to ensure that arguments are escaped prior
to calling into HCS and onwards to the Win32 CreateProcess call.
Previously, the builder was always escaping arguments which has
led to several bugs in moby. Because the local runtime in
libcontainerd had context of whether or not arguments were escaped,
it was possible to hack around in daemon/oci_windows.go with
knowledge of the context of the call (from builder or not).
With a remote runtime, this is not possible as there's rightly
no context of the caller passed across in the OCI spec. Put another
way, as I put above, the OCI spec must be unambigious.
The other previous limitation (which leads to various subtle bugs)
is that moby is coded entirely from a Linux-centric point of view.
Unfortunately, Windows != Linux. Windows CreateProcess uses a
command line, not an array of arguments. And it has very specific
rules about how to escape a command line. Some interesting reading
links about this are:
https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
https://stackoverflow.com/questions/31838469/how-do-i-convert-argv-to-lpcommandline-parameter-of-createprocess
https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments?view=vs-2017
For this reason, the OCI spec has recently been updated to cater
for more natural syntax by including a CommandLine option in
Process.
What does this commit do?
Primary objective is to ensure that the built OCI spec is unambigious.
It changes the builder so that `ArgsEscaped` as commited in a
layer is only controlled by the use of CMD or ENTRYPOINT.
Subsequently, when calling in to create a container from the builder,
if follows a different path to both `docker run` and `docker create`
using the added `ContainerCreateIgnoreImagesArgsEscaped`. This allows
a RUN from the builder to control how to escape in the OCI spec.
It changes the builder so that when shell form is used for RUN,
CMD or ENTRYPOINT, it builds (for WCOW) a more natural command line
using the original as put by the user in the dockerfile, not
the parsed version as a set of args which loses fidelity.
This command line is put into args[0] and `ArgsEscaped` is set
to true for CMD or ENTRYPOINT. A RUN statement does not commit
`ArgsEscaped` to the commited layer regardless or whether shell
or exec form were used.
2019-01-18 00:03:29 +00:00
|
|
|
// Configure the CommandLine/CommandArgs
|
2021-03-19 14:03:22 +00:00
|
|
|
setCommandLineAndArgs(spec, createProcessParms)
|
2017-09-22 13:52:41 +00:00
|
|
|
logger.Debugf("exec commandLine: %s", createProcessParms.CommandLine)
|
|
|
|
|
Windows: (WCOW) Generate OCI spec that remote runtime can escape
Signed-off-by: John Howard <jhoward@microsoft.com>
Also fixes https://github.com/moby/moby/issues/22874
This commit is a pre-requisite to moving moby/moby on Windows to using
Containerd for its runtime.
The reason for this is that the interface between moby and containerd
for the runtime is an OCI spec which must be unambigious.
It is the responsibility of the runtime (runhcs in the case of
containerd on Windows) to ensure that arguments are escaped prior
to calling into HCS and onwards to the Win32 CreateProcess call.
Previously, the builder was always escaping arguments which has
led to several bugs in moby. Because the local runtime in
libcontainerd had context of whether or not arguments were escaped,
it was possible to hack around in daemon/oci_windows.go with
knowledge of the context of the call (from builder or not).
With a remote runtime, this is not possible as there's rightly
no context of the caller passed across in the OCI spec. Put another
way, as I put above, the OCI spec must be unambigious.
The other previous limitation (which leads to various subtle bugs)
is that moby is coded entirely from a Linux-centric point of view.
Unfortunately, Windows != Linux. Windows CreateProcess uses a
command line, not an array of arguments. And it has very specific
rules about how to escape a command line. Some interesting reading
links about this are:
https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
https://stackoverflow.com/questions/31838469/how-do-i-convert-argv-to-lpcommandline-parameter-of-createprocess
https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments?view=vs-2017
For this reason, the OCI spec has recently been updated to cater
for more natural syntax by including a CommandLine option in
Process.
What does this commit do?
Primary objective is to ensure that the built OCI spec is unambigious.
It changes the builder so that `ArgsEscaped` as commited in a
layer is only controlled by the use of CMD or ENTRYPOINT.
Subsequently, when calling in to create a container from the builder,
if follows a different path to both `docker run` and `docker create`
using the added `ContainerCreateIgnoreImagesArgsEscaped`. This allows
a RUN from the builder to control how to escape in the OCI spec.
It changes the builder so that when shell form is used for RUN,
CMD or ENTRYPOINT, it builds (for WCOW) a more natural command line
using the original as put by the user in the dockerfile, not
the parsed version as a set of args which loses fidelity.
This command line is put into args[0] and `ArgsEscaped` is set
to true for CMD or ENTRYPOINT. A RUN statement does not commit
`ArgsEscaped` to the commited layer regardless or whether shell
or exec form were used.
2019-01-18 00:03:29 +00:00
|
|
|
createProcessParms.User = spec.User.Username
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
// Start the command running in the container.
|
2022-05-10 19:59:00 +00:00
|
|
|
newProcess, err := hcsContainer.CreateProcess(createProcessParms)
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.WithError(err).Errorf("exec's CreateProcess() failed")
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
defer func() {
|
2023-09-14 09:06:46 +00:00
|
|
|
if retErr != nil {
|
2017-09-22 13:52:41 +00:00
|
|
|
if err := newProcess.Kill(); err != nil {
|
|
|
|
logger.WithError(err).Error("failed to kill process")
|
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
if err := newProcess.Wait(); err != nil {
|
|
|
|
logger.WithError(err).Error("failed to wait for process")
|
|
|
|
}
|
|
|
|
if err := newProcess.Close(); err != nil {
|
|
|
|
logger.WithError(err).Error("failed to clean process resources")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-12-07 20:52:14 +00:00
|
|
|
dio, err := newIOFromProcess(newProcess, spec.Terminal)
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
2017-12-07 19:26:27 +00:00
|
|
|
logger.WithError(err).Error("failed to get stdio pipes")
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
// Tell the engine to attach streams back to the client
|
2017-12-07 19:26:27 +00:00
|
|
|
_, err = attachStdio(dio)
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p := &process{
|
|
|
|
id: processID,
|
2022-05-10 19:59:00 +00:00
|
|
|
ctr: t.ctr,
|
2017-09-22 13:52:41 +00:00
|
|
|
hcsProcess: newProcess,
|
2022-05-10 19:59:00 +00:00
|
|
|
waitCh: make(chan struct{}),
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// Spin up a goroutine to notify the backend and clean up resources when
|
|
|
|
// the process exits. Defer until after the start event is sent so that
|
|
|
|
// the exit event is not sent out-of-order.
|
|
|
|
defer func() { go p.reap() }()
|
2017-09-22 13:52:41 +00:00
|
|
|
|
2023-09-14 09:07:02 +00:00
|
|
|
pid := newProcess.Pid()
|
2022-05-10 19:59:00 +00:00
|
|
|
t.ctr.client.eventQ.Append(t.ctr.id, func() {
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
ei := libcontainerdtypes.EventInfo{
|
2022-05-10 19:59:00 +00:00
|
|
|
ContainerID: t.ctr.id,
|
2017-09-22 13:52:41 +00:00
|
|
|
ProcessID: p.id,
|
2022-05-10 19:59:00 +00:00
|
|
|
Pid: uint32(pid),
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2023-07-30 15:18:56 +00:00
|
|
|
t.ctr.client.logger.WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": t.ctr.id,
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"event": libcontainerdtypes.EventExecAdded,
|
2017-09-22 13:52:41 +00:00
|
|
|
"event-info": ei,
|
|
|
|
}).Info("sending event")
|
2022-05-10 19:59:00 +00:00
|
|
|
err := t.ctr.client.backend.ProcessEvent(t.ctr.id, libcontainerdtypes.EventExecAdded, ei)
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
2023-07-30 15:18:56 +00:00
|
|
|
t.ctr.client.logger.WithError(err).WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": t.ctr.id,
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"event": libcontainerdtypes.EventExecAdded,
|
2017-09-22 13:52:41 +00:00
|
|
|
"event-info": ei,
|
|
|
|
}).Error("failed to process event")
|
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
err = t.ctr.client.backend.ProcessEvent(t.ctr.id, libcontainerdtypes.EventExecStarted, ei)
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
2023-07-30 15:18:56 +00:00
|
|
|
t.ctr.client.logger.WithError(err).WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": t.ctr.id,
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"event": libcontainerdtypes.EventExecStarted,
|
2017-09-22 13:52:41 +00:00
|
|
|
"event-info": ei,
|
|
|
|
}).Error("failed to process event")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
return p, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *process) Pid() uint32 {
|
|
|
|
p.mu.Lock()
|
|
|
|
hcsProcess := p.hcsProcess
|
|
|
|
p.mu.Unlock()
|
|
|
|
if hcsProcess == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return uint32(hcsProcess.Pid())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *process) Kill(_ context.Context, signal syscall.Signal) error {
|
|
|
|
p.mu.Lock()
|
|
|
|
hcsProcess := p.hcsProcess
|
|
|
|
p.mu.Unlock()
|
|
|
|
if hcsProcess == nil {
|
|
|
|
return errors.WithStack(errdefs.NotFound(errors.New("process not found")))
|
|
|
|
}
|
|
|
|
return hcsProcess.Kill()
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// Kill handles `docker stop` on Windows. While Linux has support for
|
2017-09-22 13:52:41 +00:00
|
|
|
// the full range of signals, signals aren't really implemented on Windows.
|
|
|
|
// We fake supporting regular stop and -9 to force kill.
|
2022-05-10 19:59:00 +00:00
|
|
|
func (t *task) Kill(_ context.Context, signal syscall.Signal) error {
|
|
|
|
hcsContainer, err := t.getHCSContainer()
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-07-30 15:18:56 +00:00
|
|
|
logger := t.ctr.client.logger.WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": t.ctr.id,
|
|
|
|
"process": t.id,
|
|
|
|
"pid": t.Pid(),
|
2017-09-22 13:52:41 +00:00
|
|
|
"signal": signal,
|
|
|
|
})
|
|
|
|
logger.Debug("Signal()")
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
var op string
|
|
|
|
if signal == syscall.SIGKILL {
|
|
|
|
// Terminate the compute system
|
|
|
|
t.ctr.mu.Lock()
|
|
|
|
t.ctr.terminateInvoked = true
|
|
|
|
t.ctr.mu.Unlock()
|
|
|
|
op, err = "terminate", hcsContainer.Terminate()
|
2017-09-22 13:52:41 +00:00
|
|
|
} else {
|
2022-05-10 19:59:00 +00:00
|
|
|
// Shut down the container
|
|
|
|
op, err = "shutdown", hcsContainer.Shutdown()
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
if !hcsshim.IsPending(err) && !hcsshim.IsAlreadyStopped(err) {
|
|
|
|
// ignore errors
|
|
|
|
logger.WithError(err).Errorf("failed to %s hccshim container", op)
|
|
|
|
}
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// Resize handles a CLI event to resize an interactive docker run or docker
|
2017-09-22 13:52:41 +00:00
|
|
|
// exec window.
|
2022-05-10 19:59:00 +00:00
|
|
|
func (p *process) Resize(_ context.Context, width, height uint32) error {
|
|
|
|
p.mu.Lock()
|
|
|
|
hcsProcess := p.hcsProcess
|
|
|
|
p.mu.Unlock()
|
|
|
|
if hcsProcess == nil {
|
|
|
|
return errors.WithStack(errdefs.NotFound(errors.New("process not found")))
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2023-07-30 15:18:56 +00:00
|
|
|
p.ctr.client.logger.WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": p.ctr.id,
|
|
|
|
"process": p.id,
|
2017-09-22 13:52:41 +00:00
|
|
|
"height": height,
|
|
|
|
"width": width,
|
2022-05-10 19:59:00 +00:00
|
|
|
"pid": hcsProcess.Pid(),
|
2017-09-22 13:52:41 +00:00
|
|
|
}).Debug("resizing")
|
2022-05-10 19:59:00 +00:00
|
|
|
return hcsProcess.ResizeConsole(uint16(width), uint16(height))
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
func (p *process) CloseStdin(context.Context) error {
|
|
|
|
p.mu.Lock()
|
|
|
|
hcsProcess := p.hcsProcess
|
|
|
|
p.mu.Unlock()
|
|
|
|
if hcsProcess == nil {
|
|
|
|
return errors.WithStack(errdefs.NotFound(errors.New("process not found")))
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
return hcsProcess.CloseStdin()
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pause handles pause requests for containers
|
2022-05-10 19:59:00 +00:00
|
|
|
func (t *task) Pause(_ context.Context) error {
|
|
|
|
if t.ctr.ociSpec.Windows.HyperV == nil {
|
2023-04-08 17:30:33 +00:00
|
|
|
return cerrdefs.ErrNotImplemented
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
t.ctr.mu.Lock()
|
|
|
|
defer t.ctr.mu.Unlock()
|
2017-09-22 13:52:41 +00:00
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
if err := t.assertIsCurrentTask(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if t.ctr.hcsContainer == nil {
|
|
|
|
return errdefs.NotFound(errors.WithStack(fmt.Errorf("container %q not found", t.ctr.id)))
|
|
|
|
}
|
|
|
|
if err := t.ctr.hcsContainer.Pause(); err != nil {
|
2017-09-22 13:52:41 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
t.ctr.isPaused = true
|
2017-09-22 13:52:41 +00:00
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
t.ctr.client.eventQ.Append(t.ctr.id, func() {
|
|
|
|
err := t.ctr.client.backend.ProcessEvent(t.ctr.id, libcontainerdtypes.EventPaused, libcontainerdtypes.EventInfo{
|
|
|
|
ContainerID: t.ctr.id,
|
2023-01-30 18:26:26 +00:00
|
|
|
ProcessID: t.id,
|
2017-09-22 13:52:41 +00:00
|
|
|
})
|
2023-07-30 15:18:56 +00:00
|
|
|
t.ctr.client.logger.WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": t.ctr.id,
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"event": libcontainerdtypes.EventPaused,
|
2017-09-22 13:52:41 +00:00
|
|
|
}).Info("sending event")
|
|
|
|
if err != nil {
|
2023-07-30 15:18:56 +00:00
|
|
|
t.ctr.client.logger.WithError(err).WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": t.ctr.id,
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"event": libcontainerdtypes.EventPaused,
|
2017-09-22 13:52:41 +00:00
|
|
|
}).Error("failed to process event")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resume handles resume requests for containers
|
2022-05-10 19:59:00 +00:00
|
|
|
func (t *task) Resume(ctx context.Context) error {
|
|
|
|
if t.ctr.ociSpec.Windows.HyperV == nil {
|
2017-09-22 13:52:41 +00:00
|
|
|
return errors.New("cannot resume Windows Server Containers")
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
t.ctr.mu.Lock()
|
|
|
|
defer t.ctr.mu.Unlock()
|
2017-09-22 13:52:41 +00:00
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
if err := t.assertIsCurrentTask(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if t.ctr.hcsContainer == nil {
|
|
|
|
return errdefs.NotFound(errors.WithStack(fmt.Errorf("container %q not found", t.ctr.id)))
|
|
|
|
}
|
|
|
|
if err := t.ctr.hcsContainer.Resume(); err != nil {
|
2017-09-22 13:52:41 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
t.ctr.isPaused = false
|
2017-09-22 13:52:41 +00:00
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
t.ctr.client.eventQ.Append(t.ctr.id, func() {
|
|
|
|
err := t.ctr.client.backend.ProcessEvent(t.ctr.id, libcontainerdtypes.EventResumed, libcontainerdtypes.EventInfo{
|
|
|
|
ContainerID: t.ctr.id,
|
2023-01-30 18:26:26 +00:00
|
|
|
ProcessID: t.id,
|
2017-09-22 13:52:41 +00:00
|
|
|
})
|
2023-07-30 15:18:56 +00:00
|
|
|
t.ctr.client.logger.WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": t.ctr.id,
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"event": libcontainerdtypes.EventResumed,
|
2017-09-22 13:52:41 +00:00
|
|
|
}).Info("sending event")
|
|
|
|
if err != nil {
|
2023-07-30 15:18:56 +00:00
|
|
|
t.ctr.client.logger.WithError(err).WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": t.ctr.id,
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"event": libcontainerdtypes.EventResumed,
|
2017-09-22 13:52:41 +00:00
|
|
|
}).Error("failed to process event")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stats handles stats requests for containers
|
2022-05-10 19:59:00 +00:00
|
|
|
func (t *task) Stats(_ context.Context) (*libcontainerdtypes.Stats, error) {
|
|
|
|
hc, err := t.getHCSContainer()
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
readAt := time.Now()
|
2022-05-10 19:59:00 +00:00
|
|
|
s, err := hc.Statistics()
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
return &libcontainerdtypes.Stats{
|
2017-09-22 13:52:41 +00:00
|
|
|
Read: readAt,
|
|
|
|
HCSStats: &s,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// LoadContainer is the handler for restoring a container
|
|
|
|
func (c *client) LoadContainer(ctx context.Context, id string) (libcontainerdtypes.Container, error) {
|
|
|
|
c.logger.WithField("container", id).Debug("LoadContainer()")
|
2017-09-22 13:52:41 +00:00
|
|
|
|
|
|
|
// TODO Windows: On RS1, a re-attach isn't possible.
|
|
|
|
// However, there is a scenario in which there is an issue.
|
|
|
|
// Consider a background container. The daemon dies unexpectedly.
|
|
|
|
// HCS will still have the compute service alive and running.
|
|
|
|
// For consistence, we call in to shoot it regardless if HCS knows about it
|
|
|
|
// We explicitly just log a warning if the terminate fails.
|
|
|
|
// Then we tell the backend the container exited.
|
2022-05-10 19:59:00 +00:00
|
|
|
hc, err := hcsshim.OpenContainer(id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errdefs.NotFound(errors.New("container not found"))
|
|
|
|
}
|
|
|
|
const terminateTimeout = time.Minute * 2
|
|
|
|
err = hc.Terminate()
|
2017-09-22 13:52:41 +00:00
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
if hcsshim.IsPending(err) {
|
|
|
|
err = hc.WaitTimeout(terminateTimeout)
|
|
|
|
} else if hcsshim.IsAlreadyStopped(err) {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
c.logger.WithField("container", id).WithError(err).Debug("terminate failed on restore")
|
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
return &container{
|
|
|
|
client: c,
|
|
|
|
hcsContainer: hc,
|
|
|
|
id: id,
|
2019-03-25 20:17:17 +00:00
|
|
|
}, nil
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// AttachTask is only called by the daemon when restoring containers. As
|
|
|
|
// re-attach isn't possible (see LoadContainer), a NotFound error is
|
|
|
|
// unconditionally returned to allow restore to make progress.
|
|
|
|
func (*container) AttachTask(context.Context, libcontainerdtypes.StdioCallback) (libcontainerdtypes.Task, error) {
|
2023-04-08 17:30:33 +00:00
|
|
|
return nil, errdefs.NotFound(cerrdefs.ErrNotImplemented)
|
2022-05-10 19:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pids returns a list of process IDs running in a container. It is not
|
2021-08-21 18:34:21 +00:00
|
|
|
// implemented on Windows.
|
2022-05-10 19:59:00 +00:00
|
|
|
func (t *task) Pids(context.Context) ([]containerd.ProcessInfo, error) {
|
2017-09-22 13:52:41 +00:00
|
|
|
return nil, errors.New("not implemented on Windows")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Summary returns a summary of the processes running in a container.
|
|
|
|
// This is present in Windows to support docker top. In linux, the
|
|
|
|
// engine shells out to ps to get process information. On Windows, as
|
|
|
|
// the containers could be Hyper-V containers, they would not be
|
|
|
|
// visible on the container host. However, libcontainerd does have
|
|
|
|
// that information.
|
2022-05-10 19:59:00 +00:00
|
|
|
func (t *task) Summary(_ context.Context) ([]libcontainerdtypes.Summary, error) {
|
|
|
|
hc, err := t.getHCSContainer()
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
p, err := hc.ProcessList()
|
2017-09-22 13:52:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
pl := make([]libcontainerdtypes.Summary, len(p))
|
2017-09-22 13:52:41 +00:00
|
|
|
for i := range p {
|
2019-03-13 00:49:05 +00:00
|
|
|
pl[i] = libcontainerdtypes.Summary{
|
|
|
|
ImageName: p[i].ImageName,
|
|
|
|
CreatedAt: p[i].CreateTimestamp,
|
|
|
|
KernelTime_100Ns: p[i].KernelTime100ns,
|
|
|
|
MemoryCommitBytes: p[i].MemoryCommitBytes,
|
|
|
|
MemoryWorkingSetPrivateBytes: p[i].MemoryWorkingSetPrivateBytes,
|
|
|
|
MemoryWorkingSetSharedBytes: p[i].MemoryWorkingSetSharedBytes,
|
|
|
|
ProcessID: p[i].ProcessId,
|
|
|
|
UserTime_100Ns: p[i].UserTime100ns,
|
|
|
|
ExecID: "",
|
|
|
|
}
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
return pl, nil
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
func (p *process) Delete(ctx context.Context) (*containerd.ExitStatus, error) {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return nil, errors.WithStack(ctx.Err())
|
|
|
|
case <-p.waitCh:
|
|
|
|
default:
|
|
|
|
return nil, errdefs.Conflict(errors.New("process is running"))
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
return p.exited, nil
|
|
|
|
}
|
2017-09-22 13:52:41 +00:00
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
func (t *task) Delete(ctx context.Context) (*containerd.ExitStatus, error) {
|
2017-09-22 13:52:41 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, errors.WithStack(ctx.Err())
|
|
|
|
case <-t.waitCh:
|
2017-09-22 13:52:41 +00:00
|
|
|
default:
|
2022-05-10 19:59:00 +00:00
|
|
|
return nil, errdefs.Conflict(errors.New("container is not stopped"))
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
t.ctr.mu.Lock()
|
|
|
|
defer t.ctr.mu.Unlock()
|
|
|
|
if err := t.assertIsCurrentTask(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
t.ctr.task = nil
|
|
|
|
return t.exited, nil
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
func (t *task) ForceDelete(ctx context.Context) error {
|
|
|
|
select {
|
|
|
|
case <-t.waitCh: // Task is already stopped.
|
|
|
|
_, err := t.Delete(ctx)
|
|
|
|
return err
|
|
|
|
default:
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
if err := t.Kill(ctx, syscall.SIGKILL); err != nil {
|
|
|
|
return errors.Wrap(err, "could not force-kill task")
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return ctx.Err()
|
|
|
|
case <-t.waitCh:
|
|
|
|
_, err := t.Delete(ctx)
|
|
|
|
return err
|
|
|
|
}
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
func (t *task) Status(ctx context.Context) (containerd.Status, error) {
|
|
|
|
select {
|
|
|
|
case <-t.waitCh:
|
|
|
|
return containerd.Status{
|
|
|
|
Status: containerd.Stopped,
|
|
|
|
ExitStatus: t.exited.ExitCode(),
|
|
|
|
ExitTime: t.exited.ExitTime(),
|
|
|
|
}, nil
|
|
|
|
default:
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
t.ctr.mu.Lock()
|
|
|
|
defer t.ctr.mu.Unlock()
|
|
|
|
s := containerd.Running
|
|
|
|
if t.ctr.isPaused {
|
|
|
|
s = containerd.Paused
|
|
|
|
}
|
|
|
|
return containerd.Status{Status: s}, nil
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
func (*task) UpdateResources(ctx context.Context, resources *libcontainerdtypes.Resources) error {
|
2017-09-22 13:52:41 +00:00
|
|
|
// Updating resource isn't supported on Windows
|
|
|
|
// but we should return nil for enabling updating container
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
func (*task) CreateCheckpoint(ctx context.Context, checkpointDir string, exit bool) error {
|
2017-09-22 13:52:41 +00:00
|
|
|
return errors.New("Windows: Containers do not support checkpoints")
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// assertIsCurrentTask returns a non-nil error if the task has been deleted.
|
|
|
|
func (t *task) assertIsCurrentTask() error {
|
|
|
|
if t.ctr.task != t {
|
|
|
|
return errors.WithStack(errdefs.NotFound(fmt.Errorf("task %q not found", t.id)))
|
|
|
|
}
|
|
|
|
return nil
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// getHCSContainer returns a reference to the hcsshim Container for the task's
|
|
|
|
// container if neither the task nor container have been deleted.
|
|
|
|
//
|
|
|
|
// t.ctr.mu must not be locked by the calling goroutine when calling this
|
|
|
|
// function.
|
|
|
|
func (t *task) getHCSContainer() (hcsshim.Container, error) {
|
|
|
|
t.ctr.mu.Lock()
|
|
|
|
defer t.ctr.mu.Unlock()
|
|
|
|
if err := t.assertIsCurrentTask(); err != nil {
|
|
|
|
return nil, err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
hc := t.ctr.hcsContainer
|
|
|
|
if hc == nil {
|
|
|
|
return nil, errors.WithStack(errdefs.NotFound(fmt.Errorf("container %q not found", t.ctr.id)))
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
return hc, nil
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 22:09:15 +00:00
|
|
|
// ctr mutex must be held when calling this function.
|
2022-05-10 19:59:00 +00:00
|
|
|
func (ctr *container) shutdownContainer() error {
|
2018-08-02 22:09:15 +00:00
|
|
|
var err error
|
|
|
|
const waitTimeout = time.Minute * 5
|
2017-09-22 13:52:41 +00:00
|
|
|
|
2018-08-02 22:09:15 +00:00
|
|
|
if !ctr.terminateInvoked {
|
|
|
|
err = ctr.hcsContainer.Shutdown()
|
|
|
|
}
|
|
|
|
|
|
|
|
if hcsshim.IsPending(err) || ctr.terminateInvoked {
|
|
|
|
err = ctr.hcsContainer.WaitTimeout(waitTimeout)
|
2017-09-22 13:52:41 +00:00
|
|
|
} else if hcsshim.IsAlreadyStopped(err) {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
2022-05-10 19:59:00 +00:00
|
|
|
ctr.client.logger.WithError(err).WithField("container", ctr.id).
|
2017-09-22 13:52:41 +00:00
|
|
|
Debug("failed to shutdown container, terminating it")
|
2022-05-10 19:59:00 +00:00
|
|
|
terminateErr := ctr.terminateContainer()
|
Windows: Pass back system errors on container exit
Signed-off-by: John Howard <jhoward@microsoft.com>
While debugging #32838, it was found (https://github.com/moby/moby/issues/32838#issuecomment-356005845) that the utility VM in some circumstances was crashing. Unfortunately, this was silently thrown away, and as far as the build step (also applies to docker run) was concerned, the exit code was zero and the error was thrown away. Windows containers operate differently to containers on Linux, and there can be legitimate system errors during container shutdown after the init process exits. This PR handles this and passes the error all the way back to the client, and correctly causes a build step running a container which hits a system error to fail, rather than blindly trying to keep going, assuming all is good, and get a subsequent failure on a commit.
With this change, assuming an error occurs, here's an example of a failure which previous was reported as a commit error:
```
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Install-WindowsFeature -Name Web-App-Dev ; Install-WindowsFeature -Name ADLDS; Install-WindowsFeature -Name Web-Mgmt-Compat; Install-WindowsFeature -Name Web-Mgmt-Service; Install-WindowsFeature -Name Web-Metabase; Install-WindowsFeature -Name Web-Lgcy-Scripting; Install-WindowsFeature -Name Web-WMI; Install-WindowsFeature -Name Web-WHC; Install-WindowsFeature -Name Web-Scripting-Tools; Install-WindowsFeature -Name Web-Net-Ext45; Install-WindowsFeature -Name Web-ASP; Install-WindowsFeature -Name Web-ISAPI-Ext; Install-WindowsFeature -Name Web-ISAPI-Filter; Install-WindowsFeature -Name Web-Default-Doc; Install-WindowsFeature -Name Web-Dir-Browsing; Install-WindowsFeature -Name Web-Http-Errors; Install-WindowsFeature -Name Web-Static-Content; Install-WindowsFeature -Name Web-Http-Redirect; Install-WindowsFeature -Name Web-DAV-Publishing; Install-WindowsFeature -Name Web-Health; Install-WindowsFeature -Name Web-Http-Logging; Install-WindowsFeature -Name Web-Custom-Logging; Install-WindowsFeature -Name Web-Log-Libraries; Install-WindowsFeature -Name Web-Request-Monitor; Install-WindowsFeature -Name Web-Http-Tracing; Install-WindowsFeature -Name Web-Stat-Compression; Install-WindowsFeature -Name Web-Dyn-Compression; Install-WindowsFeature -Name Web-Security; Install-WindowsFeature -Name Web-Windows-Auth; Install-WindowsFeature -Name Web-Basic-Auth; Install-WindowsFeature -Name Web-Url-Auth; Install-WindowsFeature -Name Web-WebSockets; Install-WindowsFeature -Name Web-AppInit; Install-WindowsFeature -Name NET-WCF-HTTP-Activation45; Install-WindowsFeature -Name NET-WCF-Pipe-Activation45; Install-WindowsFeature -Name NET-WCF-TCP-Activation45;' returned a non-zero code: 4294967295: container shutdown failed: container ba9c65054d42d4830fb25ef55e4ab3287550345aa1a2bb265df4e5bfcd79c78a encountered an error during WaitTimeout: failure in a Windows system call: The compute system exited unexpectedly. (0xc0370106)
```
Without this change, it would be incorrectly reported such as in this comment: https://github.com/moby/moby/issues/32838#issuecomment-309621097
```
Step 3/8 : ADD buildtools C:/buildtools
re-exec error: exit status 1: output: time="2017-06-20T11:37:38+10:00" level=error msg="hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\\\?\\C:\\ProgramData\\docker\\windowsfilter\\b41d28c95f98368b73fc192cb9205700e21
6691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\\Windows\\TEMP\\hcs232661915"
hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\?\C:\ProgramData\docker\windowsfilter\b41d28c95f98368b73fc192cb9205700e216691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\Windows\TEMP\hcs232661915
```
2018-01-09 19:46:29 +00:00
|
|
|
if terminateErr != nil {
|
2022-05-10 19:59:00 +00:00
|
|
|
ctr.client.logger.WithError(terminateErr).WithField("container", ctr.id).
|
Windows: Pass back system errors on container exit
Signed-off-by: John Howard <jhoward@microsoft.com>
While debugging #32838, it was found (https://github.com/moby/moby/issues/32838#issuecomment-356005845) that the utility VM in some circumstances was crashing. Unfortunately, this was silently thrown away, and as far as the build step (also applies to docker run) was concerned, the exit code was zero and the error was thrown away. Windows containers operate differently to containers on Linux, and there can be legitimate system errors during container shutdown after the init process exits. This PR handles this and passes the error all the way back to the client, and correctly causes a build step running a container which hits a system error to fail, rather than blindly trying to keep going, assuming all is good, and get a subsequent failure on a commit.
With this change, assuming an error occurs, here's an example of a failure which previous was reported as a commit error:
```
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Install-WindowsFeature -Name Web-App-Dev ; Install-WindowsFeature -Name ADLDS; Install-WindowsFeature -Name Web-Mgmt-Compat; Install-WindowsFeature -Name Web-Mgmt-Service; Install-WindowsFeature -Name Web-Metabase; Install-WindowsFeature -Name Web-Lgcy-Scripting; Install-WindowsFeature -Name Web-WMI; Install-WindowsFeature -Name Web-WHC; Install-WindowsFeature -Name Web-Scripting-Tools; Install-WindowsFeature -Name Web-Net-Ext45; Install-WindowsFeature -Name Web-ASP; Install-WindowsFeature -Name Web-ISAPI-Ext; Install-WindowsFeature -Name Web-ISAPI-Filter; Install-WindowsFeature -Name Web-Default-Doc; Install-WindowsFeature -Name Web-Dir-Browsing; Install-WindowsFeature -Name Web-Http-Errors; Install-WindowsFeature -Name Web-Static-Content; Install-WindowsFeature -Name Web-Http-Redirect; Install-WindowsFeature -Name Web-DAV-Publishing; Install-WindowsFeature -Name Web-Health; Install-WindowsFeature -Name Web-Http-Logging; Install-WindowsFeature -Name Web-Custom-Logging; Install-WindowsFeature -Name Web-Log-Libraries; Install-WindowsFeature -Name Web-Request-Monitor; Install-WindowsFeature -Name Web-Http-Tracing; Install-WindowsFeature -Name Web-Stat-Compression; Install-WindowsFeature -Name Web-Dyn-Compression; Install-WindowsFeature -Name Web-Security; Install-WindowsFeature -Name Web-Windows-Auth; Install-WindowsFeature -Name Web-Basic-Auth; Install-WindowsFeature -Name Web-Url-Auth; Install-WindowsFeature -Name Web-WebSockets; Install-WindowsFeature -Name Web-AppInit; Install-WindowsFeature -Name NET-WCF-HTTP-Activation45; Install-WindowsFeature -Name NET-WCF-Pipe-Activation45; Install-WindowsFeature -Name NET-WCF-TCP-Activation45;' returned a non-zero code: 4294967295: container shutdown failed: container ba9c65054d42d4830fb25ef55e4ab3287550345aa1a2bb265df4e5bfcd79c78a encountered an error during WaitTimeout: failure in a Windows system call: The compute system exited unexpectedly. (0xc0370106)
```
Without this change, it would be incorrectly reported such as in this comment: https://github.com/moby/moby/issues/32838#issuecomment-309621097
```
Step 3/8 : ADD buildtools C:/buildtools
re-exec error: exit status 1: output: time="2017-06-20T11:37:38+10:00" level=error msg="hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\\\?\\C:\\ProgramData\\docker\\windowsfilter\\b41d28c95f98368b73fc192cb9205700e21
6691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\\Windows\\TEMP\\hcs232661915"
hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\?\C:\ProgramData\docker\windowsfilter\b41d28c95f98368b73fc192cb9205700e216691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\Windows\TEMP\hcs232661915
```
2018-01-09 19:46:29 +00:00
|
|
|
Error("failed to shutdown container, and subsequent terminate also failed")
|
|
|
|
return fmt.Errorf("%s: subsequent terminate failed %s", err, terminateErr)
|
|
|
|
}
|
|
|
|
return err
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-02 22:09:15 +00:00
|
|
|
// ctr mutex must be held when calling this function.
|
2022-05-10 19:59:00 +00:00
|
|
|
func (ctr *container) terminateContainer() error {
|
2017-09-22 13:52:41 +00:00
|
|
|
const terminateTimeout = time.Minute * 5
|
2018-08-02 22:09:15 +00:00
|
|
|
ctr.terminateInvoked = true
|
2017-09-22 13:52:41 +00:00
|
|
|
err := ctr.hcsContainer.Terminate()
|
|
|
|
|
|
|
|
if hcsshim.IsPending(err) {
|
|
|
|
err = ctr.hcsContainer.WaitTimeout(terminateTimeout)
|
|
|
|
} else if hcsshim.IsAlreadyStopped(err) {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
2022-05-10 19:59:00 +00:00
|
|
|
ctr.client.logger.WithError(err).WithField("container", ctr.id).
|
2017-09-22 13:52:41 +00:00
|
|
|
Debug("failed to terminate container")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
func (p *process) reap() {
|
2023-07-30 15:18:56 +00:00
|
|
|
logger := p.ctr.client.logger.WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": p.ctr.id,
|
2017-09-22 13:52:41 +00:00
|
|
|
"process": p.id,
|
|
|
|
})
|
|
|
|
|
Windows: Pass back system errors on container exit
Signed-off-by: John Howard <jhoward@microsoft.com>
While debugging #32838, it was found (https://github.com/moby/moby/issues/32838#issuecomment-356005845) that the utility VM in some circumstances was crashing. Unfortunately, this was silently thrown away, and as far as the build step (also applies to docker run) was concerned, the exit code was zero and the error was thrown away. Windows containers operate differently to containers on Linux, and there can be legitimate system errors during container shutdown after the init process exits. This PR handles this and passes the error all the way back to the client, and correctly causes a build step running a container which hits a system error to fail, rather than blindly trying to keep going, assuming all is good, and get a subsequent failure on a commit.
With this change, assuming an error occurs, here's an example of a failure which previous was reported as a commit error:
```
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Install-WindowsFeature -Name Web-App-Dev ; Install-WindowsFeature -Name ADLDS; Install-WindowsFeature -Name Web-Mgmt-Compat; Install-WindowsFeature -Name Web-Mgmt-Service; Install-WindowsFeature -Name Web-Metabase; Install-WindowsFeature -Name Web-Lgcy-Scripting; Install-WindowsFeature -Name Web-WMI; Install-WindowsFeature -Name Web-WHC; Install-WindowsFeature -Name Web-Scripting-Tools; Install-WindowsFeature -Name Web-Net-Ext45; Install-WindowsFeature -Name Web-ASP; Install-WindowsFeature -Name Web-ISAPI-Ext; Install-WindowsFeature -Name Web-ISAPI-Filter; Install-WindowsFeature -Name Web-Default-Doc; Install-WindowsFeature -Name Web-Dir-Browsing; Install-WindowsFeature -Name Web-Http-Errors; Install-WindowsFeature -Name Web-Static-Content; Install-WindowsFeature -Name Web-Http-Redirect; Install-WindowsFeature -Name Web-DAV-Publishing; Install-WindowsFeature -Name Web-Health; Install-WindowsFeature -Name Web-Http-Logging; Install-WindowsFeature -Name Web-Custom-Logging; Install-WindowsFeature -Name Web-Log-Libraries; Install-WindowsFeature -Name Web-Request-Monitor; Install-WindowsFeature -Name Web-Http-Tracing; Install-WindowsFeature -Name Web-Stat-Compression; Install-WindowsFeature -Name Web-Dyn-Compression; Install-WindowsFeature -Name Web-Security; Install-WindowsFeature -Name Web-Windows-Auth; Install-WindowsFeature -Name Web-Basic-Auth; Install-WindowsFeature -Name Web-Url-Auth; Install-WindowsFeature -Name Web-WebSockets; Install-WindowsFeature -Name Web-AppInit; Install-WindowsFeature -Name NET-WCF-HTTP-Activation45; Install-WindowsFeature -Name NET-WCF-Pipe-Activation45; Install-WindowsFeature -Name NET-WCF-TCP-Activation45;' returned a non-zero code: 4294967295: container shutdown failed: container ba9c65054d42d4830fb25ef55e4ab3287550345aa1a2bb265df4e5bfcd79c78a encountered an error during WaitTimeout: failure in a Windows system call: The compute system exited unexpectedly. (0xc0370106)
```
Without this change, it would be incorrectly reported such as in this comment: https://github.com/moby/moby/issues/32838#issuecomment-309621097
```
Step 3/8 : ADD buildtools C:/buildtools
re-exec error: exit status 1: output: time="2017-06-20T11:37:38+10:00" level=error msg="hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\\\?\\C:\\ProgramData\\docker\\windowsfilter\\b41d28c95f98368b73fc192cb9205700e21
6691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\\Windows\\TEMP\\hcs232661915"
hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\?\C:\ProgramData\docker\windowsfilter\b41d28c95f98368b73fc192cb9205700e216691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\Windows\TEMP\hcs232661915
```
2018-01-09 19:46:29 +00:00
|
|
|
var eventErr error
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
// Block indefinitely for the process to exit.
|
|
|
|
if err := p.hcsProcess.Wait(); err != nil {
|
|
|
|
if herr, ok := err.(*hcsshim.ProcessError); ok && herr.Err != windows.ERROR_BROKEN_PIPE {
|
|
|
|
logger.WithError(err).Warnf("Wait() failed (container may have been killed)")
|
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
// Fall through here, do not return. This ensures we tell the
|
|
|
|
// docker engine that the process/container has exited to avoid
|
|
|
|
// a container being dropped on the floor.
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
exitedAt := time.Now()
|
|
|
|
|
|
|
|
exitCode, err := p.hcsProcess.ExitCode()
|
|
|
|
if err != nil {
|
|
|
|
if herr, ok := err.(*hcsshim.ProcessError); ok && herr.Err != windows.ERROR_BROKEN_PIPE {
|
|
|
|
logger.WithError(err).Warnf("unable to get exit code for process")
|
|
|
|
}
|
|
|
|
// Since we got an error retrieving the exit code, make sure that the
|
|
|
|
// code we return doesn't incorrectly indicate success.
|
|
|
|
exitCode = -1
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// Fall through here, do not return. This ensures we tell the
|
|
|
|
// docker engine that the process/container has exited to avoid
|
|
|
|
// a container being dropped on the floor.
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
p.mu.Lock()
|
|
|
|
hcsProcess := p.hcsProcess
|
|
|
|
p.hcsProcess = nil
|
|
|
|
p.mu.Unlock()
|
|
|
|
|
|
|
|
if err := hcsProcess.Close(); err != nil {
|
2017-09-22 13:52:41 +00:00
|
|
|
logger.WithError(err).Warnf("failed to cleanup hcs process resources")
|
Windows: Pass back system errors on container exit
Signed-off-by: John Howard <jhoward@microsoft.com>
While debugging #32838, it was found (https://github.com/moby/moby/issues/32838#issuecomment-356005845) that the utility VM in some circumstances was crashing. Unfortunately, this was silently thrown away, and as far as the build step (also applies to docker run) was concerned, the exit code was zero and the error was thrown away. Windows containers operate differently to containers on Linux, and there can be legitimate system errors during container shutdown after the init process exits. This PR handles this and passes the error all the way back to the client, and correctly causes a build step running a container which hits a system error to fail, rather than blindly trying to keep going, assuming all is good, and get a subsequent failure on a commit.
With this change, assuming an error occurs, here's an example of a failure which previous was reported as a commit error:
```
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Install-WindowsFeature -Name Web-App-Dev ; Install-WindowsFeature -Name ADLDS; Install-WindowsFeature -Name Web-Mgmt-Compat; Install-WindowsFeature -Name Web-Mgmt-Service; Install-WindowsFeature -Name Web-Metabase; Install-WindowsFeature -Name Web-Lgcy-Scripting; Install-WindowsFeature -Name Web-WMI; Install-WindowsFeature -Name Web-WHC; Install-WindowsFeature -Name Web-Scripting-Tools; Install-WindowsFeature -Name Web-Net-Ext45; Install-WindowsFeature -Name Web-ASP; Install-WindowsFeature -Name Web-ISAPI-Ext; Install-WindowsFeature -Name Web-ISAPI-Filter; Install-WindowsFeature -Name Web-Default-Doc; Install-WindowsFeature -Name Web-Dir-Browsing; Install-WindowsFeature -Name Web-Http-Errors; Install-WindowsFeature -Name Web-Static-Content; Install-WindowsFeature -Name Web-Http-Redirect; Install-WindowsFeature -Name Web-DAV-Publishing; Install-WindowsFeature -Name Web-Health; Install-WindowsFeature -Name Web-Http-Logging; Install-WindowsFeature -Name Web-Custom-Logging; Install-WindowsFeature -Name Web-Log-Libraries; Install-WindowsFeature -Name Web-Request-Monitor; Install-WindowsFeature -Name Web-Http-Tracing; Install-WindowsFeature -Name Web-Stat-Compression; Install-WindowsFeature -Name Web-Dyn-Compression; Install-WindowsFeature -Name Web-Security; Install-WindowsFeature -Name Web-Windows-Auth; Install-WindowsFeature -Name Web-Basic-Auth; Install-WindowsFeature -Name Web-Url-Auth; Install-WindowsFeature -Name Web-WebSockets; Install-WindowsFeature -Name Web-AppInit; Install-WindowsFeature -Name NET-WCF-HTTP-Activation45; Install-WindowsFeature -Name NET-WCF-Pipe-Activation45; Install-WindowsFeature -Name NET-WCF-TCP-Activation45;' returned a non-zero code: 4294967295: container shutdown failed: container ba9c65054d42d4830fb25ef55e4ab3287550345aa1a2bb265df4e5bfcd79c78a encountered an error during WaitTimeout: failure in a Windows system call: The compute system exited unexpectedly. (0xc0370106)
```
Without this change, it would be incorrectly reported such as in this comment: https://github.com/moby/moby/issues/32838#issuecomment-309621097
```
Step 3/8 : ADD buildtools C:/buildtools
re-exec error: exit status 1: output: time="2017-06-20T11:37:38+10:00" level=error msg="hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\\\?\\C:\\ProgramData\\docker\\windowsfilter\\b41d28c95f98368b73fc192cb9205700e21
6691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\\Windows\\TEMP\\hcs232661915"
hcsshim::ImportLayer failed in Win32: The system cannot find the path specified. (0x3) layerId=\\?\C:\ProgramData\docker\windowsfilter\b41d28c95f98368b73fc192cb9205700e216691495c1f9ac79b9b04ec4923ea2 flavour=1 folder=C:\Windows\TEMP\hcs232661915
```
2018-01-09 19:46:29 +00:00
|
|
|
exitCode = -1
|
|
|
|
eventErr = fmt.Errorf("hcsProcess.Close() failed %s", err)
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
// Explicit locking is not required as reads from exited are
|
|
|
|
// synchronized using waitCh.
|
|
|
|
p.exited = containerd.NewExitStatus(uint32(exitCode), exitedAt, nil)
|
|
|
|
close(p.waitCh)
|
2017-09-22 13:52:41 +00:00
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
p.ctr.client.eventQ.Append(p.ctr.id, func() {
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
ei := libcontainerdtypes.EventInfo{
|
2022-05-10 19:59:00 +00:00
|
|
|
ContainerID: p.ctr.id,
|
2018-02-09 18:08:47 +00:00
|
|
|
ProcessID: p.id,
|
2022-05-10 19:59:00 +00:00
|
|
|
Pid: uint32(hcsProcess.Pid()),
|
2018-02-09 18:08:47 +00:00
|
|
|
ExitCode: uint32(exitCode),
|
|
|
|
ExitedAt: exitedAt,
|
|
|
|
Error: eventErr,
|
|
|
|
}
|
2023-07-30 15:18:56 +00:00
|
|
|
p.ctr.client.logger.WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": p.ctr.id,
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"event": libcontainerdtypes.EventExit,
|
2018-02-09 18:08:47 +00:00
|
|
|
"event-info": ei,
|
|
|
|
}).Info("sending event")
|
2022-05-10 19:59:00 +00:00
|
|
|
err := p.ctr.client.backend.ProcessEvent(p.ctr.id, libcontainerdtypes.EventExit, ei)
|
2018-02-09 18:08:47 +00:00
|
|
|
if err != nil {
|
2023-07-30 15:18:56 +00:00
|
|
|
p.ctr.client.logger.WithError(err).WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": p.ctr.id,
|
Windows: Experimental: Allow containerd for runtime
Signed-off-by: John Howard <jhoward@microsoft.com>
This is the first step in refactoring moby (dockerd) to use containerd on Windows.
Similar to the current model in Linux, this adds the option to enable it for runtime.
It does not switch the graphdriver to containerd snapshotters.
- Refactors libcontainerd to a series of subpackages so that either a
"local" containerd (1) or a "remote" (2) containerd can be loaded as opposed
to conditional compile as "local" for Windows and "remote" for Linux.
- Updates libcontainerd such that Windows has an option to allow the use of a
"remote" containerd. Here, it communicates over a named pipe using GRPC.
This is currently guarded behind the experimental flag, an environment variable,
and the providing of a pipename to connect to containerd.
- Infrastructure pieces such as under pkg/system to have helper functions for
determining whether containerd is being used.
(1) "local" containerd is what the daemon on Windows has used since inception.
It's not really containerd at all - it's simply local invocation of HCS APIs
directly in-process from the daemon through the Microsoft/hcsshim library.
(2) "remote" containerd is what docker on Linux uses for it's runtime. It means
that there is a separate containerd service running, and docker communicates over
GRPC to it.
To try this out, you will need to start with something like the following:
Window 1:
containerd --log-level debug
Window 2:
$env:DOCKER_WINDOWS_CONTAINERD=1
dockerd --experimental -D --containerd \\.\pipe\containerd-containerd
You will need the following binary from github.com/containerd/containerd in your path:
- containerd.exe
You will need the following binaries from github.com/Microsoft/hcsshim in your path:
- runhcs.exe
- containerd-shim-runhcs-v1.exe
For LCOW, it will require and initrd.img and kernel in `C:\Program Files\Linux Containers`.
This is no different to the current requirements. However, you may need updated binaries,
particularly initrd.img built from Microsoft/opengcs as (at the time of writing), Linuxkit
binaries are somewhat out of date.
Note that containerd and hcsshim for HCS v2 APIs do not yet support all the required
functionality needed for docker. This will come in time - this is a baby (although large)
step to migrating Docker on Windows to containerd.
Note that the HCS v2 APIs are only called on RS5+ builds. RS1..RS4 will still use
HCS v1 APIs as the v2 APIs were not fully developed enough on these builds to be usable.
This abstraction is done in HCSShim. (Referring specifically to runtime)
Note the LCOW graphdriver still uses HCS v1 APIs regardless.
Note also that this does not migrate docker to use containerd snapshotters
rather than graphdrivers. This needs to be done in conjunction with Linux also
doing the same switch.
2019-01-08 22:30:52 +00:00
|
|
|
"event": libcontainerdtypes.EventExit,
|
2017-09-22 13:52:41 +00:00
|
|
|
"event-info": ei,
|
2018-02-09 18:08:47 +00:00
|
|
|
}).Error("failed to process event")
|
|
|
|
}
|
|
|
|
})
|
2017-09-22 13:52:41 +00:00
|
|
|
}
|
2019-02-12 20:19:50 +00:00
|
|
|
|
2022-05-10 19:59:00 +00:00
|
|
|
func (ctr *container) Delete(context.Context) error {
|
|
|
|
ctr.mu.Lock()
|
|
|
|
defer ctr.mu.Unlock()
|
|
|
|
|
|
|
|
if ctr.hcsContainer == nil {
|
|
|
|
return errors.WithStack(errdefs.NotFound(fmt.Errorf("container %q not found", ctr.id)))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that there is no task currently running.
|
|
|
|
if ctr.task != nil {
|
|
|
|
select {
|
|
|
|
case <-ctr.task.waitCh:
|
|
|
|
default:
|
|
|
|
return errors.WithStack(errdefs.Conflict(errors.New("container is not stopped")))
|
2019-02-12 20:19:50 +00:00
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2023-07-30 15:18:56 +00:00
|
|
|
logger = ctr.client.logger.WithFields(log.Fields{
|
2022-05-10 19:59:00 +00:00
|
|
|
"container": ctr.id,
|
|
|
|
})
|
|
|
|
thisErr error
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := ctr.shutdownContainer(); err != nil {
|
|
|
|
logger.WithError(err).Warn("failed to shutdown container")
|
|
|
|
thisErr = errors.Wrap(err, "failed to shutdown container")
|
2019-02-12 20:19:50 +00:00
|
|
|
} else {
|
|
|
|
logger.Debug("completed container shutdown")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ctr.hcsContainer.Close(); err != nil {
|
|
|
|
logger.WithError(err).Error("failed to clean hcs container resources")
|
2022-05-10 19:59:00 +00:00
|
|
|
thisErr = errors.Wrap(err, "failed to terminate container")
|
2019-02-12 20:19:50 +00:00
|
|
|
}
|
2022-05-10 19:59:00 +00:00
|
|
|
|
|
|
|
ctr.hcsContainer = nil
|
|
|
|
return thisErr
|
2019-02-12 20:19:50 +00:00
|
|
|
}
|