Commit Graph

51364 Commits

Author SHA1 Message Date
Laurent Goderre
1126d477fd Add live-restore tests for mount image
Signed-off-by: Laurent Goderre <laurent.goderre@docker.com>
2025-02-04 21:32:04 -05:00
Laurent Goderre
90aea3b85f Add image subpath mounting functionality
Signed-off-by: Laurent Goderre <laurent.goderre@docker.com>
2025-02-04 21:32:04 -05:00
Laurent Goderre
844797348e Implement image mount for the snapshotter
Signed-off-by: Laurent Goderre <laurent.goderre@docker.com>
2025-01-31 10:34:27 -05:00
Laurent Goderre
8c58934106 Implement mount from image
Signed-off-by: Laurent Goderre <laurent.goderre@docker.com>
2025-01-31 10:34:27 -05:00
Sebastiaan van Stijn
f88304adf0 Merge pull request #49373 from thaJeztah/client_improve_error_response_handling
client: improve handling of JSON error-responses with incorrect schema
2025-01-31 13:04:39 +01:00
Rob Murray
1463c99461 Merge pull request #49364 from robmry/wait_for_bridge_forwarding
Before sending ARPs/NAs, check the bridge is ready
2025-01-30 21:50:01 +00:00
Sebastiaan van Stijn
30e75b8396 client: improve handling of JSON error-responses with incorrect schema
Before this patch, an API response that's valid JSON, but not the right
schema would be silently discarded by the CLI. For example, due to a bug
in Docker Desktop's API proxy, the "normal" (not JSON error) response
would be returned together with a non-200 status code when using an
unsupported API version;

    curl -s -w 'STATUS: %{http_code}\n' --unix-socket /var/run/docker.sock 'http://localhost/v1.99/version'
    {"Platform":{"Name":"Docker Desktop 4.38.0 (181016)"},"Version":"","ApiVersion":"","GitCommit":"","GoVersion":"","Os":"","Arch":""}
    STATUS: 400

Before this patch, this resulted in no output being shown;

    DOCKER_API_VERSION=1.99 docker version
    Client:
     Version:           27.5.1
     API version:       1.99 (downgraded from 1.47)
     Go version:        go1.22.11
     Git commit:        9f9e405
     Built:             Wed Jan 22 13:37:19 2025
     OS/Arch:           darwin/arm64
     Context:           desktop-linux
    Error response from daemon:

With this patch, an error is generated based on the status:

    DOCKER_API_VERSION=1.99 docker version
    Client:
     Version:           27.5.1
     API version:       1.99 (downgraded from 1.47)
     Go version:        go1.22.11
     Git commit:        9f9e405
     Built:             Wed Jan 22 13:37:19 2025
     OS/Arch:           darwin/arm64
     Context:           desktop-linux
    Error response from daemon: API returned a 400 (Bad Request) but provided no error-message

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-30 22:01:13 +01:00
Sebastiaan van Stijn
e82d90384e Merge pull request #49367 from thaJeztah/fix_getNetworkedContainer_errors
daemon: Daemon.getNetworkedContainer: fix errors for invalid network container
2025-01-30 21:40:33 +01:00
Rob Murray
9a6e96fd9c Before sending ARPs/NAs, check the bridge is ready
We don't enable STP on bridges belonging to bridge networks,
but bridge ports still need to transition from "disabled" to
"forwarding", after the veth device comes "up". Until then,
the bridge will just drop packets.

So, if a container's network is a veth device, and its other
end is slaved to a bridge - wait for the bridge port to
be "forwarding".

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-30 20:40:01 +00:00
Sebastiaan van Stijn
a5db4280d8 Merge pull request #49368 from thaJeztah/rmlink_nofuzzy
daemon: Daemon.rmLink: don't fuzzy-match container when using ID
2025-01-30 19:04:44 +01:00
Sebastiaan van Stijn
8860e98d1a Merge pull request #49369 from thaJeztah/daemon_remove_wrappers
daemon: remove Daemon.children(), Daemon.parents() wrappers
2025-01-30 18:04:41 +01:00
Sebastiaan van Stijn
e7f5d73fa5 Merge pull request #49354 from thaJeztah/client_test_coverage
client: improve test-coverage for error-responses
2025-01-30 17:07:00 +01:00
Sebastiaan van Stijn
5b5ad4df2c Merge pull request #49352 from thaJeztah/api_version_prefix
client: WithVersion: strip v-prefix when setting API version
2025-01-30 17:04:31 +01:00
Sebastiaan van Stijn
52ea449c55 daemon: Daemon.restore: make legacy-link code conditional
Make it more clear that this loop is for legacy-links, and the timer is
only needed for that purpose.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-30 14:23:10 +01:00
Sebastiaan van Stijn
9a69161992 daemon: remove Daemon.children(), Daemon.parents() wrappers
Remove the wrappers to make it more explicit that these are related to
the legacy links feature.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-30 14:23:10 +01:00
Sebastiaan van Stijn
513fd86710 daemon: Daemon.getNetworkedContainer: fix errors for invalid network container
When failing to resolve the network container, a "not found" error should
not return a 404, but either a "invalid parameter" (400) or "system" (500)
error.

Given that this function is called on container start, not container create,
a 500 (internal server error) is more appropriate, because the API request
(start the container) is valid, but the state of the container isn't.

While working on this, I discovered that no validation happens during container
create; TODO's were added to look into that, but this may be partially
by design (allow a container to be created before the "donor" network
container is created).

Before this patch:

    docker container create --name hello --network=container:nosuchcontainer alpine
    docker container start hello
    Error response from daemon: No such container: nosuchcontainer
    Error: failed to start containers: hello

    # daemon logs:
    DEBU[2025-01-30T11:32:33.595636043Z] error response for POST request               error-response="No such container: nosuchcontainer" method=POST module=api request-url=/v1.47/containers/hello/start status=404 vars="map[name:hello version:1.47]"

    docker container create --name hello2 --network=container:hello2 alpine
    docker container start hello2
    Error response from daemon: cannot join own network
    Error: failed to start containers: hello2

    # daemon logs:
    DEBU[2025-01-30T11:33:19.545287551Z] FIXME: Got an API for which error does not match any expected type!!!  error="cannot join own network" error_type="*errors.errorString" module=api
    DEBU[2025-01-30T11:33:19.545346093Z] error response for POST request               error-response="cannot join own network" method=POST module=api request-url=/v1.47/containers/hello2/start status=500 vars="map[name:hello2 version:1.47]"
    DEBU[2025-01-30T11:33:19.545369968Z] FIXME: Got an API for which error does not match any expected type!!!  error="cannot join own network" error_type="*errors.errorString" module=api
    ERRO[2025-01-30T11:33:19.545375426Z] Handler for POST /v1.47/containers/hello2/start returned error: cannot join own network

With this patch:

    docker container create --name hello --network=container:nosuchcontainer alpine
    docker container start hello
    Error response from daemon: joining network of container: No such container: nosuchcontainer
    Error: failed to start containers: hello

    # daemon logs:
    DEBU[2025-01-30T11:35:50.406462760Z] error response for POST request               error-response="joining network of container: No such container: nosuchcontainer" method=POST module=api request-url=/v1.47/containers/hello/start status=500 vars="map[name:hello version:1.47]"
    ERRO[2025-01-30T11:35:50.406501468Z] Handler for POST /v1.47/containers/hello/start returned error: joining network of container: No such container: nosuchcontainer

    docker container create --name hello2 --network=container:hello2 alpine
    docker container start hello2
    Error response from daemon: cannot join own network namespace
    Error: failed to start containers: hello2

    # daemon logs:
    DEBU[2025-01-30T11:36:15.178475049Z] error response for POST request               error-response="cannot join own network" method=POST module=api request-url=/v1.47/containers/hello2/start status=500 vars="map[name:hello2 version:1.47]"
    ERRO[2025-01-30T11:36:15.178536507Z] Handler for POST /v1.47/containers/hello2/start returned error: cannot join own network

    docker run --name exitedcontainer alpine
    docker run --rm --network=container:exitedcontainer alpine
    docker: Error response from daemon: cannot join network namespace of a non running container: container exitedcontainer is exited.

    # daemon logs:
    DEBU[2025-01-30T12:54:28.040637429Z] error response for POST request               error-response="cannot join network namespace of a non running container: container exitedcontainer is exited" method=POST module=api request-url=/v1.47/containers/hello2/start status=409 vars="map[name:hello2 version:1.47]"

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-30 14:18:33 +01:00
Sebastiaan van Stijn
51cb066ec8 daemon: Daemon.rmLink: don't fuzzy-match container when using ID
rmLink already looked up the parent container's ID, so we should not use
daemon.GetContainer to resolve the container, as that performs fuzzy
matching (name, ID-prefix, or ID).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-30 11:39:19 +01:00
Sebastiaan van Stijn
c42005e944 Merge pull request #49356 from thaJeztah/client_reduce_test_deps
client: remove uses of pkg/errors in tests
2025-01-29 23:26:23 +01:00
Paweł Gronowski
e273a5635a Merge pull request #49355 from thaJeztah/api_types_less_deps
api/types: remove some redundant imports
2025-01-29 15:28:41 +01:00
Sebastiaan van Stijn
dcaf8cb805 Merge pull request #47649 from vvoland/dev-completions
Dockerfile: Use CLI generated completions in the dev shell
2025-01-29 13:03:34 +01:00
Sebastiaan van Stijn
9b5a51a881 api/types/container: remove use of errdefs package in test
It was the only use of errdefs inside api/types, which is the package
that's imported by external users.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-29 12:36:40 +01:00
Sebastiaan van Stijn
02eb72380f client: remove uses of pkg/errors in tests
While there may be reasons to keep pkg/errors in production
code, we don't need them for these tests.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-29 11:53:16 +01:00
Sebastiaan van Stijn
3f354e8c1b api/types/registry: use stdlib errors package
It was the only use of github.com/pkg/errors inside api/types,
which is the package that's imported by external users.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-29 11:51:29 +01:00
Sebastiaan van Stijn
0ca0ccd37a client: improve test-coverage for error-responses
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-29 11:47:25 +01:00
Sebastiaan van Stijn
04f9d3e5fe Merge pull request #49349 from thaJeztah/bridge_clean_errors
libnetwork/drivers/bridge: remove, or internalize errors
2025-01-28 22:33:18 +01:00
Sebastiaan van Stijn
97b50bca2c client: WithVersion: strip v-prefix when setting API version
When overriding the API version through DOCKER_API_VERSION, no validation
happens on the given version. However, some code-paths in the client do
some minor normalizing, and strip the "v" prefix (if present) as part of
[`Client.getAPIPath()`][1].

This resulted in some inconsistent handling of the version that's set. For
example,  [`Client.checkResponseErr()`][2] decides whether or not the API
response is expected to support errors in JSON format (`types.ErrorResponse`),
which would fail because `versions.GreaterThan()` does not strip the prefix,
therefore making the first element "zero" (ranking lower than any valid version).

Net result was "mixed" because of this; for example in the following, half
the output is handled correctly ("downgraded from 1.47"), but the response
is handled as < 1.23 (so printed as-is);

    DOCKER_API_VERSION=v1.23 docker version
    Client: Docker Engine - Community
     Version:           27.5.1
     API version:       v1.23 (downgraded from 1.47)
     Go version:        go1.22.11
     Git commit:        9f9e405
     Built:             Wed Jan 22 13:41:13 2025
     OS/Arch:           linux/amd64
     Context:           default
    Error response from daemon: {"message":"client version 1.23 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version"}

Passing the version without v-prefix corrects this problem;

    DOCKER_API_VERSION=1.23 docker version
    Client: Docker Engine - Community
     Version:           27.5.1
     API version:       1.99 (downgraded from 1.47)
     Go version:        go1.22.11
     Git commit:        9f9e405
     Built:             Wed Jan 22 13:41:13 2025
     OS/Arch:           linux/amd64
     Context:           default
    Error response from daemon: client version 1.99 is too new. Maximum supported API version is 1.47

    DOCKER_API_VERSION=v1.99 docker version
    Client: Docker Engine - Community
     Version:           27.5.1
     API version:       v1.99 (downgraded from 1.47)
     Go version:        go1.22.11
     Git commit:        9f9e405
     Built:             Wed Jan 22 13:41:13 2025
     OS/Arch:           linux/amd64
     Context:           default
    Error response from daemon: {"message":"client version 1.99 is too new. Maximum supported API version is 1.47"}

This patch strips the prefix when setting a custom version, so that
normalization happens consistently. The existing code to strip the
prefix in [`Client.getAPIPath()`][1] is kept for now, in case values
are set through other ways.

[1]: 47dc8d5dd8/client/client.go (L303-L309)
[2]: 47dc8d5dd8/client/request.go (L231-L241)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 21:32:23 +01:00
Sebastiaan van Stijn
bbaa8af8f3 libnetwork/drivers/bridge: un-export errors
These errors implement errdefs interfaces, and are only used internally
for convenience. Un-export their implemetations because the types themselves
are not used as sentinel errors.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:12:42 +01:00
Sebastiaan van Stijn
3f9698e1f6 libnetwork/drivers/bridge: TestLinkDelete: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:12:42 +01:00
Sebastiaan van Stijn
74fd2ec0cf libnetwork/drivers/bridge: TestLinkCreateNoEnableIPv6: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:12:37 +01:00
Sebastiaan van Stijn
6e9ba725f8 libnetwork/drivers/bridge: TestLinkCreateTwo: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:15 +01:00
Sebastiaan van Stijn
bf3323fd40 libnetwork/drivers/bridge: TestLinkCreate: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:15 +01:00
Sebastiaan van Stijn
7012e3ce14 libnetwork/drivers/bridge: remove NonDefaultBridgeExistError
It was only used in a single place, and a generic errdefs.ErrInvalid; the
type itself was not used as sentinel error other than for a unit test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:15 +01:00
Sebastiaan van Stijn
47f6d4e1bc libnetwork/drivers/bridge: internalize ErrInvalidGateway
It's a generic errdefs.ErrInvalidParameter, and the type itself is not
used as sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
3a9f4e0146 libnetwork/drivers/bridge: remove ErrInvalidMtu
It's a generic errdefs.ErrInvalidParameter, and the type itself is not
used as sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
2f42aa0e26 libnetwork/drivers/bridge: remove IPv4AddrNoMatchError
It's a generic error, doesn't implement an errdefs type, and not used as
sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
0c1b660048 libnetwork/drivers/bridge: remove IPv4AddrAddError
It's a generic error, doesn't implement an errdefs type, and not used as
sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
dc52ecb1d0 libnetwork/drivers/bridge: remove ErrNoIPAddr
It's a generic error, doesn't implement an errdefs type, and not used as
sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
77261b5e42 libnetwork/drivers/bridge: remove "InternalError()" method from errors
The `InternalError()` method was added in [moby/libnetwork@50964c9] to
classify the error. However, the same commit defined interfaces for error
types (in the types package). The [InternalError] interface defined did
not match, as it defines a `Internal()` method instead of `InternalError()`.

In short; these errors were never matching any interface, and the actual
error implementations themselves were also never used as a sentinel error,
so we can safely remove these methods.

[moby/libnetwork@50964c9]: 50964c9948
[InternalError]: 50964c9948/types/types.go (L233-L237)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:13 +01:00
Sebastiaan van Stijn
2766298f49 libnetwork/drivers/bridge: remove unused errors
This removes the following errors, which were not used anywhere;

- ErrConfigExists
- ErrInvalidNetworkConfig
- ErrInvalidEndpointConfig
- ErrNetworkExists
- ErrIfaceName
- ErrUnsupportedAddressType
- NonDefaultBridgeNeedsIPError
- IPv6AddrNoMatchError

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:13 +01:00
Sebastiaan van Stijn
59c2d2a4b3 libnetwork/drivers/bridge: remove ErrInvalidDriverConfig
It's a generic error, doesn't implement an errdefs type, is poorly formatted,
and not used as sentinel error anywhere. Let's remove it, and update the error
produced to be slightly more informative (include the invalid type). Worth
noting that there's no need to include the name of the driver in the error,
because the only uses of the error (in `registerNetworkDrivers`) already
decorates it; 5fd7ed2937/libnetwork/drivers_linux.go (L34-L36)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:11 +01:00
Sebastiaan van Stijn
47dc8d5dd8 Merge pull request #49325 from akerouanton/fix-45610-v2
libnet/d/bridge: drop connections to lo mappings, and direct remote connections
2025-01-28 16:38:29 +01:00
Sebastiaan van Stijn
beb5fa6acc Merge pull request #49350 from thaJeztah/windows_clean_errors
libnetwork/drivers/windows: remove ErrUnsupportedAddressType
2025-01-28 16:30:49 +01:00
Sebastiaan van Stijn
1c22f5d3d7 Merge pull request #49347 from thaJeztah/libnetwork_options_gotest
libnetwork/options: rewrite tests with gotest.tools
2025-01-28 16:28:45 +01:00
Sebastiaan van Stijn
6bb9f581a5 libnetwork/drivers/windows: remove ErrUnsupportedAddressType
It was only used in a single place, and did not implement an errdef;
the type itself was not used as sentinel error.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 15:14:27 +01:00
Paweł Gronowski
54a969d1a4 Dockerfile: Use CLI generated completions in the dev shell
Use Cobra-generated completion scripts for the CLI inside the dev
container shell.

Remove `DOCKER_BASH_COMPLETION_PATH`.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-01-28 14:28:20 +01:00
Sebastiaan van Stijn
510e6f4f8a libnetwork/options: rewrite tests with gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 12:27:44 +01:00
Sebastiaan van Stijn
5fd7ed2937 Merge pull request #49342 from robmry/debug_flaky_unsol_na
Debug flaky unsolicited Neighbour Advertisements
2025-01-28 12:14:38 +01:00
Albin Kerouanton
ac23dddac0 Merge pull request #49302 from robmry/create_veth_in_container
Create bridge veth in container netns
2025-01-28 11:47:33 +01:00
Sebastiaan van Stijn
f760738a15 Merge pull request #49336 from thaJeztah/no_strslice
remove redundant uses of api/types/strslice.StrSlice
2025-01-27 21:33:11 +01:00
Albin Kerouanton
a42b601c31 Merge pull request #49343 from thaJeztah/cluster_cleanup_networkattachment
daemon/cluster/executor: simplify handling of Network Attachments
2025-01-27 18:47:29 +01:00