582 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
6b4dfb0135 integration-cli: migrate TestPostContainersCreateShmSizeXXX to integration
Some of these tests were making assumptions about the daemon's internals
by using `config.DefaultShmSize` from the daemon config package.

Rewrite them to start a daemon with a custom default, and verify the
tests to use that default.

This migrates the following tests from integration-cli to integration;

- `DockerAPISuite.TestPostContainersCreateShmSizeNegative`
- `DockerAPISuite.TestPostContainersCreateShmSizeHostConfigOmitted`
- `DockerAPISuite.TestPostContainersCreateShmSizeOmitted`
- `DockerAPISuite.TestPostContainersCreateWithShmSize`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-26 20:52:00 +02:00
Sebastiaan van Stijn
ca1c5ee08f pkg/stringid: move to daemon, and provide copy in client
The stringid package is used in many places; while it's trivial
to implement a similar utility, let's just provide it as a utility
package in the client, removing the daemon-specific logic.

For integration tests, I opted to use the implementation in the
client, as those should not ideally not make assumptions about
the daemon implementation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-25 13:39:32 +02:00
Derek McGowan
c74ba95583 Move oci to daemon/pkg/oci
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:11:19 -07:00
Muhammad Daffa Dinaya
6e7a2c830d Add Health attribute on the docker ps command
Signed-off-by: Muhammad Daffa Dinaya <muhammaddaffadinaya@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-21 22:57:03 +02:00
Sebastiaan van Stijn
20d594fb79 deprecate pkg/stdcopy, move to api/stdcopy
The stdcopy package is used to produce and read multiplexed streams for
"attach" and "logs". It is used both by the API server (to produce), and
the client (to read / de-multiplex).

Move it to the api package, so that it can be included in the api module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-21 21:41:39 +02:00
Derek McGowan
c47afd41c8 Create github.com/moby/moby/client module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-21 09:30:26 -07: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
Derek McGowan
04f5276267 Move volume to daemon/volume
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-15 10:44:44 -07:00
Paweł Gronowski
649256a269 Merge pull request #50387 from thaJeztah/flaky_TestRemoveContainerWithVolume
integration/container: fix flaky TestRemoveContainerWithVolume
2025-07-14 16:14:44 +02:00
Sebastiaan van Stijn
fd8fec18cd integration/container: XFAIL flaky TestExecResize on Windows
This test is failing frequently (50%) on Windows;

    === FAIL: github.com/docker/docker/integration/container TestExecResize/success (0.01s)
        exec_test.go:144: assertion failed: error is not nil: Error response from daemon: NotFound: exec: '9c19c467436132df24d8b606b0c462b1110dacfbbd13b63e5b42579eda76d7fc' in task: '7d1f371218285a0c653ae77024a1ab3f5d61a5d097c651ddf7df97364fafb454' not found: not found

Let's keep the test, but log the failure and skip on Windows.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-13 15:13:16 +02:00
Sebastiaan van Stijn
d6c90dcb87 integration/container: fix flaky TestRemoveContainerWithVolume
This test depended on the container to die after running the `true` command,
but this condition failed frequently on Windows 2025.

    === Failed
    === FAIL: github.com/docker/docker/integration/container TestRemoveContainerWithVolume (32.68s)
        remove_test.go:61: timeout hit after 10s: waiting for container State.Status to be 'exited', currently 'running'

While this may be revealing an actual issue (and we should have a test for
that), it's irrelevant for this test, which;

- creates and starts a container with an anonymous volume
- verifies the anonymous volume was created
- removes the container
- verifies the anonymous volume was removed

We can force-remove the container to kill, and removed it; we probably
could've sufficed with "container create" (without starting), but it's
good to add extra coverage, in case running the container impacts whether
we're able to remove the volume.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-12 15:58:27 +02:00
Sebastiaan van Stijn
dde698a2e8 integration/container: add basic test for ContainerInspectWithRaw
Make sure we have basic coverage for this function; integration-cli may
have additional tests covering this as well.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-11 15:00:19 +02:00
Sebastiaan van Stijn
a5e3f39770 integration/container: avoid ContainerInspectWithRaw with "size"
These tests didn't use the raw output, and didn't use the size.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-11 13:01:56 +02:00
Sebastiaan van Stijn
88b67eb2fc integration/container: cleanup TestCreateWithCustomReadonlyPaths
- Use ContainerInspect instead of manually unmarshaling the raw JSON
- Explicitly stop the container instead of polling for it to die
- Add test for privileged containers
- Use subtests and run parallel

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-11 12:51:54 +02:00
Sebastiaan van Stijn
bd091c1a9d integration/container: cleanup TestCreateWithCustomMaskedPaths
- Use ContainerInspect instead of manually unmarshaling the raw JSON
- Explicitly stop the container instead of polling for it to die
- Use subtests and run parallel

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-11 12:51:30 +02:00
Derek McGowan
5419eb1efc Move container to daemon/container
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-06-27 14:27:21 -07:00
Sebastiaan van Stijn
53475e1adf integration/container: TestCreateByImageID: minor improvements
- Assert that we're not using empty IDs
- stringid.TruncateID already truncates algorithm, so we can just feed
  it the full id
- Fail early on error, and skip asserting the `resp.ID` to reduce some
  noise;

    === FAIL: github.com/docker/docker/integration/container TestCreateByImageID/image_short-ID (60.33s)
        create_test.go:134: assertion failed: resp.ID is ""
        create_test.go:135: assertion failed: error is not nil: error during connect: Post "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.48/containers/create": EOF

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-06-23 12:19:44 +02:00
Sebastiaan van Stijn
0c182d4d57 api/types/container: deprecate ExecOptions.Detach
This field was added in 5130fe5d38, which
added it for use as intermediate struct when parsing CLI flags (through
`runconfig.ParseExec`) in c786a8ee5e.

Commit 9d9dff3d0d rewrote the CLI to use
Cobra, and as part of this introduced a separate `execOptions` type in
`api/client/container`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-06-17 12:38:33 +02:00
Matthieu MOREL
6d737371b8 fix comparison rule from errorlint
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-06-13 08:26:56 +00:00
Sebastiaan van Stijn
d3d20b9195 integration-cli: TestCopyFromContainerPathIsNotDir: adjust for win 2025
It looks like the error returned by Windows changed in Windows 2025; before
Windows 2025, this produced a `ERROR_INVALID_NAME`;

    The filename, directory name, or volume label syntax is incorrect.

But Windows 2025 produces a `ERROR_DIRECTORY` ("The directory name is invalid."):

    CreateFile \\\\?\\Volume{d9f06b05-0405-418b-b3e5-4fede64f3cdc}\\windows\\system32\\drivers\\etc\\hosts\\: The directory name is invalid.

Docs; https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-06-12 15:18:17 +02:00
Sebastiaan van Stijn
4970333621 integration: remove // import comments
These comments were added to enforce using the correct import path for
our packages ("github.com/docker/docker", not "github.com/moby/moby").
However, when working in go module mode (not GOPATH / vendor), they have
no effect, so their impact is limited.

Remove these imports in preparation of migrating our code to become an
actual go module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-30 15:59:14 +02:00
Matthieu MOREL
14852fcd82 integration: replace uses of errdefs package
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-05-28 05:39:50 +00:00
Sebastiaan van Stijn
3d1e4d9002 api/types: move build-related types to api/types/build
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-19 09:30:27 +02:00
Sebastiaan van Stijn
bb7dbaafcd api/types: move BuildResult to api/types/build.Result
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-17 00:39:09 +02:00
Paweł Gronowski
9095698a5c daemon: Discover devices and include in system info
Add ability for the device driver to implement a device discovery
mechanism and expose discovered devices in the `docker info` output.

Currently it's only implemented for CDI devices.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-05-16 17:03:29 +02:00
Paweł Gronowski
4cecce03f6 daemon: Enable CDI by default
CDI will now be enabled by default unless opted-out by setting `cdi`
feature to `false`.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-05-15 22:13:19 +02:00
Sebastiaan van Stijn
3bbdda696d use container.ContainerState consts in tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-13 15:03:34 +02:00
Sebastiaan van Stijn
9b19172c7f Merge pull request #49868 from thaJeztah/exec_validate_user
docker exec: fail early on exec create if specified user doesn't exist
2025-05-09 17:00:50 +02:00
Matthieu MOREL
27bf320a72 fix(ST1017): Don’t use Yoda conditions
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-05-01 14:17:59 +02:00
Rob Murray
8d5177b229 Merge pull request #49876 from thaJeztah/pseudo_type_healthstatus
api/types/container: define HealthStatus "pseudo" type
2025-04-28 13:43:50 +01:00
Sebastiaan van Stijn
1e4bb14bcd api/types/container: define HealthStatus "pseudo" type
It currently is an alias for string, but may become a distinct type in future.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-26 15:26:26 +02:00
Sebastiaan van Stijn
c690e0076a use consts for health-status in tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-26 15:05:26 +02:00
Sebastiaan van Stijn
b54a038bec docker exec: fail early on exec create if specified user doesn't exist
Before this patch, and error would be produced when starting the exec,
but the CLI would wait for the exec to complete, timing out after 10
seconds (default). With this change, an error is returned immediately
when creating the exec.

Note that "technically" this check may have some TOCTOU issues, because
'/etc/passwd' and '/etc/groups' may be mutated by the container in between
creating the exec and starting it.

This is very likely a corner-case, but something we can consider changing
in future (either allow creating an invalid exec, and checking before
starting, or checking both before create and before start).

With this patch:

    printf 'FROM alpine\nRUN rm -f /etc/group' | docker build -t nogroup -
    ID=$(docker run -dit nogroup)

    time docker exec -u 0:root $ID echo hello
    Error response from daemon: unable to find group root: no matching entries in group file

    real	0m0.014s
    user	0m0.010s
    sys	0m0.003s

    # numericc uid/gid (should not require lookup);
    time docker exec -u 0:0 $ID echo hello
    hello

    real	0m0.059s
    user	0m0.007s
    sys	0m0.008s

    # no user specified (should not require lookup);
    time docker exec $ID echo hello
    hello

    real	0m0.057s
    user	0m0.013s
    sys	0m0.008s

    docker rm -fv $ID

    # container that does have a valid /etc/groups

    ID=$(docker run -dit alpine)
    time docker exec -u 0:root $ID echo hello
    hello

    real	0m0.063s
    user	0m0.010s
    sys	0m0.009s

    # non-existing user or group
    time docker exec -u 0:blabla $ID echo hello
    Error response from daemon: unable to find group blabla: no matching entries in group file

    real	0m0.013s
    user	0m0.004s
    sys	0m0.009s

    docker rm -fv $ID

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-25 15:24:00 +02:00
Sebastiaan van Stijn
eede75c9d4 testing: remove some defer cleanup in favor of test.Cleanup()
gotest.tools v3.0.1 and up support Go's native test.Cleanup(), which
means that manually calling the cleanup functions in a defer is no
longer needed.

Some of these could probably be replaced by Go's native `t.TempDir()`,
but keeping that for a follow-up exercise.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-19 16:35:24 +02:00
Paweł Gronowski
c49ce64514 integration/TestStopContainerWithTimeout: Attempt to fix flakiness
Temporarily remove Parallel.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-04-14 12:31:52 +02:00
Derek McGowan
d0154d3e59 Update to use github.com/moby/go-archive
Update use of idtools to moby/user for archive and other deprecated uses

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-04-08 17:35:05 -07:00
Paweł Gronowski
ac34bd9bda integration/container: Remove Parallel from TestWait*
It seems to help with the flakiness in the CI.
However, I can't reproduce the flakiness locally.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-03-13 18:09:32 +01:00
Paweł Gronowski
dd7f9f08d8 integration/container: Increase stop timeout for TestWaitRestartedContainer
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-03-13 18:09:29 +01:00
Rob Murray
97c397112a Merge pull request #49560 from ctalledo/mask-thermal-interrupt-info
Mask Linux thermal interrupt info in /proc and /sys.
2025-03-13 15:16:34 +00:00
Paweł Gronowski
64b72a8db1 Merge pull request #49365 from ctalledo/47581-fix
Improve performance of daemon.Containers()
2025-03-12 18:28:55 +00:00
Sebastiaan van Stijn
a8f14e06d6 Improve performance of daemon.Containers().
Improve performance of function daemon.Containers() (used by docker ps) to
mitigate a latency increase when running large number of containers using the
containerd image store.

We do this by refactoring daemon.Containers() to collect info for containers in
parallel, rather than sequentially, using up to log2(N) worker threads. This
improves the performance from O(N) to O(log2(N)), where N is the number of
containers.

To verify correctness, this commits adds unit and integration tests.

Signed-off-by: Cesar Talledo <cesar.talledo@docker.com>
2025-03-12 09:59:52 -07:00
Cesar Talledo
a3fef5debc Mask Linux thermal interrupt info in /proc and /sys.
On Linux, mask "/proc/interrupts" and "/sys/devices/system/cpu/cpu<x>/thermal_throttle"
inside containers by default. Privileged containers or containers started
with --security-opt="systempaths=unconfined" are not affected.

Mitigates potential Thermal Side-Channel Vulnerability Exploit
(https://github.com/moby/moby/security/advisories/GHSA-6fw5-f8r9-fgfm).

Also: improve integration test TestCreateWithCustomMaskedPaths() to ensure
default masked paths don't apply to privileged containers.

Signed-off-by: Cesar Talledo <cesar.talledo@docker.com>
2025-03-10 17:18:10 -07:00
Paweł Gronowski
2124706447 integration: Increase timeouts in TestStopContainerWithTimeout
To reduce flakiness

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-03-10 17:04:33 +01:00
Paweł Gronowski
946bf70f89 integration: Deduplicate TestStopContainerWithTimeout
The test had 2 almost identical separate  implementations (Linux and
Windows). The Windows one was skipped anyway.
Make one test that covers all test cases.

The test still needs to be fixed for Windows, so don't unskip it yet.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-03-10 17:04:29 +01:00
Cesar Talledo
c9f53d506a Merge ps_test.go into list_test.go.
Signed-off-by: Cesar Talledo <cesar.talledo@docker.com>
2025-03-06 10:42:07 -08:00
Paweł Gronowski
6abe6a910a integration/container: adjust "gotest.tools/v3/assert/cmp" import alias
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-03-03 19:11:42 +01:00
Sebastiaan van Stijn
60782e6d39 container: fix some errors on Windows
While going through some logs from CI, I noticed this log-entry on Windows,
produced as part of a test;

    2025-02-25T03:23:17.6584227Z [Error] Handler for POST /v1.48/containers/b47b1e632188426d6d42a4be04f9a3cc1eca40cfed9536d277011052af0b04f5/update returned error: Cannot update container b47b1e632188426d6d42a4be04f9a3cc1eca40cfed9536d277011052af0b04f5: Restart policy cannot be updated because AutoRemove is enabled for the container

While updating is an error for the user, it's not an error in the daemon,
so we should return the correct error-type (and avoid logging it as an
error in daemon logs).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-25 17:53:25 +01:00
Jonathan A. Sternberg
927e07e46e API: add Platform (OS and Architecture) to /containers/json
Adds platform information to containers (for `docker ps`).

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-02-13 14:52:21 -06:00
Paweł Gronowski
a096045678 all: Replace deprecated ImageInspectWithRaw usage
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-02-06 13:31:48 +01:00
Sebastiaan van Stijn
433e9a50ce Merge pull request #48828 from vbatts/cgroups-rw
daemon/&container/: enable `--security-opt writable-cgroups=true|false` as an option
2025-01-23 20:41:08 +01:00