Repository navigation
daemon: Add embedded containerd mode - #52898
Conversation
thaJeztah
left a comment
There was a problem hiding this comment.
🎉 nice! Most things are pretty straightforward AFAICS (🎉)
Need to have a closer look, but things to look for;
- Configuration and storage locations; we currently ignore the
--containerd=/run/containerd/containerd.sockoption, which (maybe?) means we may have both running; what storage do we use? Should it error out? - ☝️ probably the tricky bit; how to adjust our systemd units to make the containerd service optional (prevent it from being started as required dependency)
From a UX perspective; we should also look if we can include the information about the containerd instance in docker version (components) and docker info;
- make it clear we're using the embedded containerd runtime
- include the version of the module in the output (both API and containerd modules?)
- if configured to be exposed; we need to surface listeners in the api (I need to dust off my PR that does this)
Server: Docker Desktop 4.79.0 (229644)
Engine:
Version: 29.5.3
API version: 1.54 (minimum version 1.40)
Go version: go1.26.4
Git commit: 285b471
Built: Wed Jun 3 18:00:14 2026
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v2.2.4
GitCommit: 193637f7ee8ae5f5aa5248f49e7baa3e6164966e
runc:
And the output of docker info (we really need to consider deprecating those fields fully);
Runtimes: runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: 193637f7ee8ae5f5aa5248f49e7baa3e6164966e
runc version: v1.3.5-0-g488fc13e
init version: de40ad0
| if cli.Config.Features["embedded-containerd"] { | ||
| return cli.initEmbeddedContainerd(ctx) | ||
| } | ||
| if cli.Config.ContainerdAddr != "" { | ||
| // use system containerd at the given address. | ||
| return nil, nil | ||
| } | ||
|
|
There was a problem hiding this comment.
So I think ultimately, we want to change this to "use the embedded containerd, unless a container-socket is configured" (in which case we use the provided socket / system instance).
So we could swap the order here, but of course that makes testing slightly more cumbersome, as we should error if both are set (?) so require the systemd config to be modified / a drop-in (override) to be created to remove that config;
moby/contrib/init/systemd/docker.service
Lines 12 to 15 in b4f5a9f
There was a problem hiding this comment.
Yeah for now I think it's better to just make the feature flag take precedence, to avoid having to modify the systemd service
There was a problem hiding this comment.
Alternative name could be builtin (but that's just bike-shedding)
There was a problem hiding this comment.
Yeah was thinking about it. builtin would probably make more sense for the case where we actually drop the gRPC and use containerd directly.
| // Address returns the containerd gRPC address (unix socket path, or named | ||
| // pipe on Windows) external clients and tooling should dial. | ||
| Address() string |
There was a problem hiding this comment.
(reading through the diff, so maybe it's already there)
- This should probably be opt-in, and not the default
- We could also expose everything through the
docker.sockas an option I guess? (if we don't want to explode the list of sockets, and have a single point of entry) - Do we want the possibility to configure multiple (similar to dockerd being able to listen on multiple addresses)?
| @@ -1740,6 +1850,7 @@ go.opentelemetry.io/otel/internal/baggage | |||
| go.opentelemetry.io/otel/internal/errorhandler | |||
| go.opentelemetry.io/otel/internal/global | |||
| go.opentelemetry.io/otel/propagation | |||
| go.opentelemetry.io/otel/semconv/v1.17.0 | |||
There was a problem hiding this comment.
Ah derp; which one was it this time?
Oh; maybe this goes away with containerd 2.3 vendoring; ISTR I made some changes to drop the old semconv ones 🤔
There was a problem hiding this comment.
It's containerd/otelttrpc; I had a PR to update it, but maybe it's possible to remove it entirely;
| github.com/Azure/azure-sdk-for-go/sdk/internal v1.12.0 // indirect | ||
| github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.5.0 // indirect | ||
| github.com/ProtonMail/go-crypto v1.3.0 // indirect | ||
| github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect |
There was a problem hiding this comment.
Hm... probably need to check what's bringing in this one
There was a problem hiding this comment.
Used by
Which is imported here;
Used here;
| k8s.io/apimachinery v0.34.1 h1:dTlxFls/eikpJxmAC7MVE8oOeP1zryV7iRyIjB0gky4= | ||
| k8s.io/apimachinery v0.34.1/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw= |
There was a problem hiding this comment.
:sadpanda: - let's see what improvements we can make w.r.t. dependencies we pull in and if we can avoid some of them. (assuming we don't want to expose the CRI APIs)
There was a problem hiding this comment.
Coming from
Imported in
- Introduced in Support for cgroups blockio containerd/containerd#5490
Looks like it's only strictly needed for some consts used by ContainerClassFromAnnotations -> kubernetes.ContainerClassFromAnnotations 🫠
|
CI is mostly green with the exception of Windows 🎉 Failures on Windows, but not sure if actual failure or just flakiness; both tests have PRs pending to migrate them (but also ran into some issues there ISTR):
Not sure about this one; These could be path conversions (not taking the GUID volume paths into account?) |
|
OH; one more on Windows .. could be some error from hcsshim? |
|
Ah; probably needs an adjustment in the moby/integration/networking/drivers_windows_test.go Lines 219 to 227 in b4f5a9f // ErrNotSupported is an error encountered when hcs doesn't support the request
ErrPlatformNotSupported = errors.New("unsupported platform request") |
|
Other tests as well; they're also skipped with containerd integration (but maybe needs looking into); moby/integration-cli/docker_api_stats_test.go Lines 26 to 29 in b4f5a9f |
55cf032 to
262c58b
Compare
262c58b to
fc029bd
Compare
|
Add a build tag opt-out ( |
fc029bd to
ca66bcc
Compare
28086e9 to
eaf544e
Compare
| } | ||
|
|
||
| func listen(address string) (net.Listener, error) { | ||
| if err := os.MkdirAll(filepath.Dir(address), 0o700); err != nil { |
There was a problem hiding this comment.
If we control the life-cycle, we should make sure this code is called after the directory is created, and not create it here.
| // Remove any stale socket left behind by a previous run. | ||
| if err := os.RemoveAll(address); err != nil { | ||
| return nil, err | ||
| } |
There was a problem hiding this comment.
We should probably unlink instead to avoid removing directories or unrelated content
Actually thinking; should we use
moby/vendor/github.com/docker/go-connections/sockets/unix_socket.go
Lines 58 to 66 in 2df6b4b
Or .. even
moby/vendor/github.com/docker/go-connections/sockets/inmem_socket.go
Lines 30 to 34 in 2df6b4b
| } | ||
|
|
||
| func (l *inMemoryListener) Addr() net.Addr { | ||
| return &net.UnixAddr{Name: "embedded-containerd", Net: "unix"} |
There was a problem hiding this comment.
Wondering if we should something identifiable here?
return &net.UnixAddr{Name: "embedded-containerd", Net: "inmem"}
| if err := os.RemoveAll(address); err != nil { | ||
| return nil, err | ||
| } | ||
| return net.Listen("unix", address) |
There was a problem hiding this comment.
Also looking at permissions for this one (which go-connections would allow handling
| // are registered in server.go. | ||
| _ "github.com/containerd/containerd/v2/plugins/diff/lcow" | ||
| _ "github.com/containerd/containerd/v2/plugins/diff/windows" | ||
| _ "github.com/containerd/containerd/v2/plugins/snapshots/windows" |
There was a problem hiding this comment.
curious if native would also be used on Windows (not even sure now if we currently support vfs on windows.
Fine for a follow-up to tweak these though!
(slightly considering if we should have separate files for the registration bits, but also fine for a follow-up)
There was a problem hiding this comment.
No, native won't work on Windows
The supervisor (managed-containerd lifecycle) package manages a containerd server rather than the libcontainerd client, so group them under a new daemon/internal/containerd/server parent. Signed-off-by: Paweł Gronowski <[email protected]>
Run containerd inside dockerd when the experimental `embedded-containerd` feature is enabled through `--feature` or the daemon configuration. Serve containerd's gRPC API on a Unix socket, or a named pipe on Windows, for the plugin executor and external tools. Use an in-memory listener for dockerd's own containerd client. Serve TTRPC on a platform endpoint so task shims can publish events. Register only the containerd plugins dockerd needs. Leave CRI, sandbox, streaming, transfer, NRI, and the restart monitor out of the embedded server. Reject `--cri-containerd` when embedded mode is enabled instead of silently ignoring the requested CRI support. Check the feature before `ContainerdAddr` so it can override the default containerd socket supplied by packaged service units. Continue to use the configured external containerd when the feature is disabled. Derive the Windows named-pipe address from the daemon state directory so multiple daemons can run on the same host. Restrict the pipes to the built-in Administrators group and LocalSystem with the same protected DACL as dockerd's API pipe, as the default security descriptor depends on the process token and can expose the containerd endpoints more broadly than intended. Treat embedded mode as a containerd runtime in the Windows test environment. Add the `no_embedded_containerd` build tag so distributors can omit the embedded plugin graph and its dependencies. Signed-off-by: Paweł Gronowski <[email protected]>
Route BuildKit's worker (and the Windows executor) over the in-memory pipe instead of the unix socket. Signed-off-by: Paweł Gronowski <[email protected]>
Add an "embedded" mode to the Linux and Windows integration test matrices that runs the daemon with the embedded-containerd feature. Signed-off-by: Paweł Gronowski <[email protected]>
Fork containerd's `cmd/containerd/server` bootstrap into the embedded package instead of vendoring it, so dockerd owns the plugin graph and the server lifecycle and only pulls in what the embedded server needs. The forked server also shuts down cleanly: closing only the ttrpc listener leaves accepted shim connections and their request contexts alive after the embedded containerd stops, so cancel the server context and close the ttrpc server before tearing down plugins. This also lets the server own listener closure and avoids concurrent Close calls during shutdown. Signed-off-by: Paweł Gronowski <[email protected]>
Embedded containerd always derives its persistent root from Docker's data root, which prevents testing against state from a standalone containerd daemon. Use DOCKER_CONTAINERD_ROOT as a temporary override for the exact root path used by embedded and supervised containerd. Preserve the existing data-root/containerd/daemon default when the variable is unset. Signed-off-by: Paweł Gronowski <[email protected]>
eaf544e to
6d2a425
Compare
| google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect | ||
| gopkg.in/inf.v0 v0.9.1 // indirect | ||
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| k8s.io/apimachinery v0.36.0 // indirect |
There was a problem hiding this comment.
:sadpanda: to get this in our tree (didn't look yet where it's used)
There was a problem hiding this comment.
Needs some refactoring on the containerd side
| github.com/blang/semver v3.5.1+incompatible // indirect | ||
| github.com/cenkalti/backoff/v5 v5.0.3 // indirect | ||
| github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||
| github.com/checkpoint-restore/checkpointctl v1.5.0 // indirect |
There was a problem hiding this comment.
Slightly same for this one I guess (still experimental on our side, but not sure where used in the c8d code)
There was a problem hiding this comment.
It comes from core/runtime/v2/shim.go - can't avoid it on our side
There was a problem hiding this comment.
https://github.com/containerd/containerd/blob/7e217685fb9acd7d2802e3b6033aee6018db35f7/core/runtime/v2/shim.go#L645 heh, looks like it's only used for a const? 😄
There was a problem hiding this comment.
LOL, that's something we should fix in upstream
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM
As follow-ups;
- see if we can swap out those sockets for go-connections?
- work on fixing those upstream dependency issues (at least for that const!)
It's already done: |

Summary
NOTE: This is the easier, lower-risk of two ways to embed containerd.
It still speaks gRPC to itself over an in-memory pipe, so the daemon's existing containerd client is reused unchanged and only the transport differs.
The cost is that requests still go through gRPC codecs (protobuf marshal/unmarshal over a memory buffer).
The ideal target is to drop the gRPC layer entirely and call containerd's services as direct in-process Go calls (via client.WithInMemoryServices). With no pipe, no dialer, no marshaling.
Add an experimental embedded containerd mode, enabled with the embedded-containerd feature (--feature embedded-containerd, or "features": {"embedded-containerd": true} in daemon.json).
Instead of starting and supervising a separate containerd process, the daemon runs containerd's full server in-process via server.New.
The in-process server is reached over two endpoints:
containerd's ttrpc endpoint is also served, so task shims can publish events.
/flaky-test=TestWaitNonBlocked
Release notes (optional)
A picture of a cute animal (not mandatory but encouraged)