Commit Graph

1144 Commits

Author SHA1 Message Date
Rob Murray
282868dabf NRI: instantiate and start/stop NRI adaptation
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-12-08 16:11:59 +00:00
Derek McGowan
e4a1657762 Check containerd client before using on Windows
Throw an error if the containerd snapshotter is enabled on Windows but
containerd has not been configured. This fixes a panic in this case when
trying to use an uninitialized client.

Signed-off-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-11-26 15:40:08 +01:00
Rob Murray
e757bbb4ea Move call to Daemon.registerLinks out of Daemon.setHostConfig
The call from Daemon.create -> Daemon.setHostConfig acquired
container.Lock, but didn't need to because the container is
newly created and solely owned by the caller. The call from
Daemon.restore did not acquire the lock.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-11-16 18:20:12 +00:00
Paweł Gronowski
391247ce96 daemon: Fix image store choice priority for prior graphdriver state
The priority order for determining image store choice was incorrect when
a prior graphdriver existed.

The issue occurred because the prior graphdriver check happened after
processing explicit driver configuration, effectively ignoring user
intent when prior state existed.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-11-13 10:05:49 +01:00
Sebastiaan van Stijn
7e78088f8f daemon: remove workaround for c8d client connection timeout
This workaround was added in df519e9e1a, pending
a fix in containerd;

> daemon: Fix giving up too early while connecting to containerd socket
>
> Explicitly set the gRPC connection params to take the timeout into
> account to workaround the containerd v2 client not passing down the
> stack.
>
> containerd v2 replaced usages of deprecated gRPC functions but didn't
> pass the timeout to the actual dial connection options.

A fix for this was merged in [containerd@ee574e7], which is part of containerd
v2.1.0-beta.0, and backported to containerd v2.0.4 through [containerd@6b5efba].

[containerd@ee574e7]: ee574e76e7
[containerd@6b5efba]: 6b5efba83b

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-11 17:55:44 +01:00
Vigilans
d192a63467 daemon: Ensure buildkit created container's isolation mode consistent with daemon's config
- Introduced DefaultIsolation method in the Daemon to return the daemon configured isolation mode for Windows.

Signed-off-by: Vigilans <vigilans@foxmail.com>
2025-11-10 16:33:14 +01:00
Sebastiaan van Stijn
048ced8435 Merge pull request #51448 from akerouanton/stop-events-service
daemon: close EventsService on shutdown
2025-11-10 14:20:28 +01:00
Albin Kerouanton
d087d3c057 daemon: close EventsService on shutdown
On daemon shutdown, the HTTP server tries to gracefully shutdown for 5
seconds. If there's an open API connection to the '/events' endpoint, it
fails to do so as nothing interrupts that connection, thus forcing the
daemon to wait until that timeout is reached.

Add a Close method to the EventsService, and call it during daemon
shutdown. It'll close any events channel, signaling to the '/events'
handler to return and close the connection.

It now takes ~1s (or less) to shutdown the daemon when there's an active
'/events' connection, instead of 5.

Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
2025-11-09 22:38:59 +01:00
Sebastiaan van Stijn
fb94e241f5 daemon: disk-usage: fix incorrect key for singleflight
commit a69abdd90d introduced a "verbose"
option for the disk-usage endpoint, which allowed omitting the items
to be included in the results.

However, it did not take into account that a singleflight is used to
allow sharing the results between requests; this means that a request
made while another request is already in flight could share the wrong
results, and either get "verbose" or "non-verbose", depending on the
request already in flight.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-07 21:21:32 +01:00
Paweł Gronowski
10f6eeb56d daemon: Refactor image store choice logic
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-11-06 20:09:27 +01:00
Austin Vazquez
a69abdd90d api/types/system: add type specific usage fields to DiskUsage
This change adds type specific fields to `GET /system/df` endpoint with high level information of disk usage. This change also introduces `verbose` query to the endpoint so that detailed information is by default excluded unless queried to reduce memory consumption. The previous top level `DiskUsage` fields (`Images`, `Containers`, `Volumes` and `BuildCache`) are now deprecated and kept for backwards compatibility.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-11-03 16:34:26 -06:00
Derek McGowan
600edfe55c Move container platform migration logic
Defer the logic to fill in the container platform information from the
image service until container restore. During container restore the
image backend is fully initialized and can be used to fill in the
missing platform fields for older containers.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-10-20 10:39:16 -07:00
Paweł Gronowski
4181d934be Merge pull request #50869 from vvoland/c8d-fix-windows-migration
daemon: Fix unwanted c8d migration on Windows
2025-09-25 11:13:39 +00:00
Sebastiaan van Stijn
0df791cb72 explicitly access Container.State instead of through embedded struct
The Container.State struct holds the container's state, and most of
its fields are expected to change dynamically. Some o these state-changes
are explicit, for example, setting the container to be "stopped". Other
state changes can be more explicit, for example due to the containers'
process exiting or being "OOM" killed by the kernel.

The distinction between explicit ("desired") state changes and "state"
("actual state") is sometimes vague; for some properties, we clearly
separated them, for example if a user requested the container to be
stopped or restarted, we store state in the Container object itself;

    HasBeenManuallyStopped   bool // used for unless-stopped restart policy
    HasBeenManuallyRestarted bool `json:"-"` // used to distinguish restart caused by restart policy from the manual one

Other properties are more ambiguous. such as "HasBeenStartedBefore" and
"RestartCount", which are stored on the Container (and persisted to
disk), but may be more related to "actual" state, and likely should
not be persisted;

    RestartCount             int
    HasBeenStartedBefore     bool

Given that (per the above) concurrency must be taken into account, most
changes to the `container.State` struct should be protected; here's where
things get blurry. While the `State` type provides various accessor methods,
only some of them take concurrency into account; for example, [State.IsRunning]
and [State.GetPID] acquire a lock, whereas [State.ExitCodeValue] does not.
Even the (commonly used) [State.StateString] has no locking at all.

The way to handle this is error-prone; [container.State] contains a mutex,
and it's exported. Given that its embedded in the [container.Container]
struct, it's also exposed as an exported mutex for the container. The
assumption here is that by "merging" the two, the caller to acquire a lock
when either the container _or_ its state must be mutated. However, because
some methods on `container.State` handle their own locking, consumers must
be deeply familiar with the internals; if both changes to the `Container`
AND `Container.State` must be made. This gets amplified more as some
(exported!) methods, such as [container.SetRunning] mutate multiple fields,
but don't acquire a lock (so expect the caller to hold one), but their
(also exported) counterpart (e.g. [State.IsRunning]) do.

It should be clear from the above, that this needs some architectural
changes; a clearer separation between "desired" and "actual" state (opening
the potential to update the container's config without manually touching
its `State`), possibly a method to obtain a read-only copy of the current
state (for those querying state), and reviewing which fields belong where
(and should be persisted to disk, or only remain in memory).

This PR preserves the status quo; it makes no structural changes, other
than exposing where we access the container's state. Where previously the
State fields and methods were referred to as "part of the container"
(e.g. `ctr.IsRunning()` or `ctr.Running`), we now explicitly reference
the embedded `State` (`ctr.State.IsRunning`, `ctr.State.Running`).

The exception (for now) is the mutex, which is still referenced through
the embedded struct (`ctr.Lock()` instead of `ctr.State.Lock()`), as this
is (mostly) by design to protect the container, and what's in it (including
its `State`).

[State.IsRunning]: c4afa77157/daemon/container/state.go (L205-L209)
[State.GetPID]: c4afa77157/daemon/container/state.go (L211-L216)
[State.ExitCodeValue]: c4afa77157/daemon/container/state.go (L218-L228)
[State.StateString]: c4afa77157/daemon/container/state.go (L102-L131)
[container.State]: c4afa77157/daemon/container/state.go (L15-L23)
[container.Container]: c4afa77157/daemon/container/container.go (L67-L75)
[container.SetRunning]: c4afa77157/daemon/container/state.go (L230-L277)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-19 16:02:14 +02:00
Paweł Gronowski
f8925bac6f daemon: Do not default to c8d image store on Windows
Before this commit migration to c8d would apply when
`TEST_INTEGRATION_USE_GRAPHDRIVER` is empty/unset (which is the default
scenario).

This caused fresh Windows installations to default to containerd image
store and panic:

```
PS C:\Users\Administrator\Desktop> .\dockerd.exe --debug
time="2025-09-01T12:45:42.182741200Z" level=info msg="Starting up"
time="2025-09-01T12:45:42.225128900Z" level=debug msg="Listener created for HTTP on npipe (//./pipe/docker_engine)"
time="2025-09-01T12:45:42.231740900Z" level=info msg="OTEL tracing is not configured, using no-op tracer provider"
time="2025-09-01T12:45:42.263475300Z" level=info msg="Windows default isolation mode: process"
time="2025-09-01T12:45:42.263475300Z" level=debug msg="Stackdump - waiting signal at Global\\stackdump-7780"
time="2025-09-01T12:45:42.273230800Z" level=debug msg="Using default logging driver json-file"
time="2025-09-01T12:45:42.273230800Z" level=debug msg="No quota support for local volumes in C:\\ProgramData\\docker\\volumes: Filesystem does not support, or has not enabled quotas"
time="2025-09-01T12:45:42.301881100Z" level=info msg="Loading containers: start."
time="2025-09-01T12:45:42.302302800Z" level=info msg="[graphdriver] trying configured driver: windowsfilter"
time="2025-09-01T12:45:42.302302800Z" level=debug msg="WindowsGraphDriver InitFilter at C:\\ProgramData\\docker\\windowsfilter"
time="2025-09-01T12:45:42.303028000Z" level=debug msg="Initialized graph driver windowsfilter"
time="2025-09-01T12:45:42.323007600Z" level=info msg="Enabling containerd snapshotter because migration set with no containers and 0 images in graph driver" total=0
time="2025-09-01T12:45:42.323007600Z" level=info msg="Starting daemon with containerd snapshotter integration enabled"
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x88 pc=0x16522c4]

goroutine 1 [running]:
github.com/containerd/containerd/v2/client.(*Client).IntrospectionService(0x3153e60?)
        /go/src/github.com/docker/docker/vendor/github.com/containerd/containerd/v2/client/client.go:731 +0x24
github.com/moby/moby/v2/daemon.NewDaemon({0x3153e60, 0xc0001360f0}, 0xc0000fa008, 0xc00025c5a0, 0xc0002deee0)
        /go/src/github.com/docker/docker/daemon/daemon.go:1276 +0x35ad
github.com/moby/moby/v2/daemon/command.(*daemonCLI).start(0xc0000da320, {0x3153df0, 0x4704c60})
        /go/src/github.com/docker/docker/daemon/command/daemon.go:262 +0xa09
github.com/moby/moby/v2/daemon/command.runDaemon({0x3153df0, 0x4704c60}, 0xc0000da320)
        /go/src/github.com/docker/docker/daemon/command/docker_windows.go:28 +0x8a
github.com/moby/moby/v2/daemon/command.newDaemonCommand.func1(0xc000147508, {0xc000500f60?, 0x7?, 0x2cf8c90?})
        /go/src/github.com/docker/docker/daemon/command/docker.go:45 +0xd1
github.com/spf13/cobra.(*Command).execute(0xc000147508, {0xc00006a0f0, 0x1, 0x1})
        /go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1015 +0xaaa
github.com/spf13/cobra.(*Command).ExecuteC(0xc000147508)
        /go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1148 +0x46f
github.com/spf13/cobra.(*Command).Execute(...)
        /go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1071
github.com/spf13/cobra.(*Command).ExecuteContext(...)
        /go/src/github.com/docker/docker/vendor/github.com/spf13/cobra/command.go:1064
github.com/moby/moby/v2/daemon/command.daemonRunner.Run({0x3127160?}, {0x3153df0, 0x4704c60})
        /go/src/github.com/docker/docker/daemon/command/docker.go:111 +0x6e
main.main()
        /go/src/github.com/docker/docker/cmd/dockerd/main.go:38 +0x122
```

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-09-09 18:24:50 +02:00
Sebastiaan van Stijn
4d20b6fe56 api/types/container: move container options to client
Move the option-types to the client and in some cases create a
copy for the backend. These types are used to construct query-
args, and not marshaled to JSON, and can be replaced with functional
options in the client.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-04 20:09:55 +02:00
Albin Kerouanton
18efa5513d libnet: makeDriverConfig: drop support for label-based config
makeDriverConfig is written in such a way that it seems to support
label-based driver configuration. That is, you could hypothetically use
labels starting with `com.docker.network.driver.<driver-name>.` to
define the configuration of a driver.

These labels come from the Controller's `cfg.Labels` which are set by
the daemon through libnet's OptionLabels which takes the list of labels
set on the daemon through dockerd's --label flag, or the equivalent
daemon.json field.

However, the daemon forbids setting labels that start with
`com.docker.*`. For instance:

    label com.docker.network.driver.bridge.EnableProxy=false is not allowed: the namespaces com.docker.*, io.docker.*, and org.dockerproject.* are reserved for internal use

Hence, this is dead code — remove it.

Also, makeDriverConfig is checking if the Controller's cfg field is
nil... But the Controller struct is instantiated in a single place (i.e.
NewController) and it always set that field. Drop that nil check too.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-09-03 11:23:07 +02:00
Austin Vazquez
ea126c0541 Merge pull request #50760 from vvoland/c8d-default-notsomuch
daemon: Fix forceful switch to containerd image store
2025-08-21 12:26:35 -07:00
Paweł Gronowski
86ae7a56d2 daemon: Fix container restore with automatic driver selection
Fix a bug causing containers not being loaded when storage driver wasn't
chosen explicitly.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-08-20 11:20:51 +02:00
Paweł Gronowski
555e3939c9 daemon: Fix forceful switch to containerd image store
When no explicit driver was specified, the containerd store by default
was also applied to existing graphdriver setups.

Fix this and add a test.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-08-20 11:20:50 +02:00
Austin Vazquez
c4e82bab70 api/types/volume: move DiskUsage type internal to daemon backend
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-08-19 08:12:34 -05:00
Austin Vazquez
566c44edfe api/types/container: move DiskUsage type internal to daemon backend
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-08-19 07:59:46 -05:00
Austin Vazquez
b2e6fd31cf Restore DOCKER_DRIVER environment variable for storage driver configuration.
This change restores the environment variable configuration of daemon storage driver through the DOCKER_DRIVER environment variable.

Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-08-12 16:35:31 -05:00
Austin Vazquez
0ca1bc036f Merge pull request #48009 from dmcgowan/containerd-migration
Update containerd to default storage and add support for migration
2025-08-11 13:33:14 -07:00
Derek McGowan
a4fbbc1570 Add context to restore and load containers
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-08-11 08:47:24 -07:00
Derek McGowan
4816383c0b Add environment variable to define the threshold
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-08-11 08:47:22 -07:00
Marat Radchenko
0ded8645b6 Fix custom runtimes handling on Windows
This commit partially reverts 7ccf750daa and 84965c0752

Closes #50542

Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
2025-08-08 21:41:17 +02:00
Derek McGowan
632fb0c89a Update graphdriver check logic to account for disabling of snapshotter
Ensure migration is never attempted multiple times.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-08-08 12:07:42 -07:00
Derek McGowan
b41babafaa Fix windows test graphdriver setting
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-08-08 12:07:42 -07:00
Derek McGowan
7f87cf9d8a Check for snapshotter plugin availability
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-08-08 12:07:41 -07:00
Derek McGowan
632de98f75 Enable containerd snapshotters by default
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-08-08 12:07:41 -07:00
Derek McGowan
9f5f4f5a42 Add containerd migration to daemon startup
Add layer migration on startup
Use image size threshold rather than image count
Add daemon integration test
Add test for migrating to containerd snapshotters
Add vfs migration
Add tar export for containerd migration
Add containerd migration test with save and load

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-08-08 12:07:23 -07:00
Sebastiaan van Stijn
78ccee32b3 update various "doc" links in code
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-05 20:49:57 +02:00
Sebastiaan van Stijn
cf15d5bbc6 remove obsolete //go:build tags
These are no longer needed as these are now part of a module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-01 00:49:22 +02:00
Derek McGowan
f74e5d48b3 Create github.com/moby/moby/v2 module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-31 10:13:29 -07:00
Sebastiaan van Stijn
1313b8caff pkg/fileutils: move ReadSymlinkedDirectory to daemon
It has no external consumers, is written with specific behavior, making
it not a good candidate to carry in the module.

This moves it to the daemon as a non-exported `resolveSymlinkedDirectory`
utility, so that it's only accessible where it's currently used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-29 11:17:32 +02:00
Sebastiaan van Stijn
83510a26b3 api/types: move backend types to daemon/server
The "backend" types in API were designed to decouple the API server
implementation from the daemon, or other parts of the code that
back the API server. This would allow the daemon to evolve (e.g.
functionality moved to different subsystems) without that impacting
the API server's implementation.

Now that the API server is no longer part of the API package (module),
there is no benefit to having it in the API module. The API server
may evolve (and require changes in the backend), which has no direct
relation with the API module (types, responses); the backend definition
is, however, coupled to the API server implementation.

It's worth noting that, while "technically" possible to use the API
server package, and implement an alternative backend implementation,
this has never been a prime objective. The backend definition was
never considered "stable", and we don't expect external users to
(attempt) to use it as such.

This patch moves the backend types to the daemon/server package,
so that they can evolve with the daemon and API server implementation
without that impacting the API module (which we intend to be stable,
following SemVer).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-28 00:03:04 +02:00
Derek McGowan
ca5d2348d0 Move pkg/idtools to daemon/internal/idtools
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:12:07 -07:00
Derek McGowan
7bfb804dbe Move registry to daemon/pkg/registry
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:11:51 -07:00
Derek McGowan
f1f83dae55 Move reference to daemon/internal/refstore
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:11:35 -07:00
Derek McGowan
f24455c90b Move image to daemon/internal/image
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:11:02 -07:00
Derek McGowan
1ff6011e04 Move distribution to daemon/internal/distribution
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:10:46 -07:00
Derek McGowan
fa9a3c383d Move layer to daemon/internal/layer
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:10:30 -07:00
Albin Kerouanton
f996384932 Merge pull request #50382 from akerouanton/split-nat-routed-portmappers
libnet/d/bridge: mv portmapper to libnet/pms/{nat,routed}
2025-07-22 15:45:52 +02:00
Albin Kerouanton
4e246efcd1 libnet/d/bridge: mv portmapper to libnet/pms/{nat,routed}
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-07-22 12:37:01 +02:00
Derek McGowan
afd6487b2e Create github.com/moby/moby/api module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-21 09:30:05 -07:00
Austin Vazquez
f776cd6922 Merge pull request #50367 from dmcgowan/move-volume-daemon
Move volume under daemon
2025-07-17 14:21:06 -07:00
Rob Murray
2f4f78bd3c Merge pull request #50327 from Adrien-Atmosphere/50326-wait-for-dependent-containers
Wait for container dependencies upon daemon start up
2025-07-17 20:24:34 +01:00
Rob Murray
8c79486dab Merge pull request #50357 from robmry/firewall_backend_option
Add daemon option --firewall-backend
2025-07-17 19:21:12 +01:00
Adrien Pompée
d4e026fe20 Wait for container dependencies upon daemon start up
- Get dependent containers before starting containers
- Dependent containers can be either from legacy link or container network
- Wait on a best effort basis for the dependent containers

Fixes: #50326

Signed-off-by: Adrien Pompée <adrien.pompee@atmosphere.aero>
2025-07-17 19:41:39 +02:00