Compare commits

...

470 Commits

Author SHA1 Message Date
Paweł Gronowski
e953d76450 Merge pull request #48060 from thaJeztah/27.0_backport_api_deprecate_ContainerJSONBase_Node
[27.0 backport] api/types: deprecate ContainerJSONBase.Node, ContainerNode
2024-06-26 20:30:43 +02:00
Paweł Gronowski
861fde8cc9 Merge pull request #48061 from thaJeztah/27_backport_bump_golangci_lint
[27.0 backport] update golangci-lint to v1.59.1
2024-06-26 19:14:38 +02:00
Sebastiaan van Stijn
3557077867 update golangci-lint to v1.59.1
full diff: https://github.com/golangci/golangci-lint/compare/v1.55.2...v1.59.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 95fae036ae)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-26 14:09:41 +02:00
Sebastiaan van Stijn
c95b917167 pkg/archive: reformat code to make #nosec comment work again
Looks like the way it picks up #nosec comments changed, causing the
linter error to re-appear;

    pkg/archive/archive_linux.go:57:17: G305: File traversal when extracting zip/tar archive (gosec)
                    Name:       filepath.Join(hdr.Name, WhiteoutOpaqueDir),
                                ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit d4160d5aa7)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-26 14:09:41 +02:00
Sebastiaan van Stijn
c0ff08acbd builder/remotecontext: reformat code to make #nosec comment work again
Looks like the way it picks up #nosec comments changed, causing the
linter error to re-appear;

    builder/remotecontext/remote.go:48:17: G107: Potential HTTP request made with variable url (gosec)
        if resp, err = http.Get(address); err != nil {
                       ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 04bf0e3d69)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-26 14:09:41 +02:00
Sebastiaan van Stijn
4587688258 api/types: deprecate ContainerJSONBase.Node, ContainerNode
The `Node` field and related `ContainerNode` type were used by the classic
(standalone) Swarm API. API documentation for this field was already removed
in 234d5a78fe (API 1.41 / docker 20.10), and
as the Docker Engine didn't implement these fields for the Swarm API, it
would always have been unset / nil.

Let's do a quick deprecation, and remove it on the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 1fc9236119)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-26 14:05:47 +02:00
Paweł Gronowski
ff1e2c0de7 Merge pull request #48050 from thaJeztah/deprecate_graphdriver_plugins
deprecate experimental Graphdriver plugins, and disable by default
2024-06-21 15:12:12 +02:00
Sebastiaan van Stijn
6da604aa6a deprecate experimental Graphdriver plugins, and disable by default
Graphdriver plugins] are an experimental feature that allow extending the
Docker Engine with custom storage drivers for storing images and containers.
This feature was not maintained since its inception, and will no longer be
supported in upcoming releases.

Users of this feature are recommended to instead configure the Docker Engine
to use the [containerd image store], and a custom [snapshotter].

This patch:

- Disables loading graphdriver plugins by default, producing an error instead.
- Introduces a temporary `DOCKERD_DEPRECATED_GRAPHDRIVER_PLUGINS` environment
  variable to re-enable the deprecated features; this allows users to still
  use the feature on a v27.0 daemon, but disabling it by default will give a
  strong message that it will no longer be supported.

[Graphdriver plugins]: https://github.com/docker/cli/blob/v26.1.4/docs/extend/plugins_graphdriver.md
[containerd image store]: https://docs.docker.com/storage/containerd/
[snapshotter]: https://github.com/containerd/containerd/tree/v1.7.18/docs/snapshotters

Before this patch (ignore the "Unable to load plugin" errors, as there's no plugin);

    dockerd --experimental -s my-driver
    ...
    INFO[2024-06-21T10:42:49.574901255Z] containerd successfully booted in 0.011384s
    INFO[2024-06-21T10:42:50.575891922Z] [graphdriver] trying configured driver: my-driver
    WARN[2024-06-21T10:42:50.576121547Z] Unable to locate plugin: my-driver, retrying in 1s
    WARN[2024-06-21T10:42:51.577131506Z] Unable to locate plugin: my-driver, retrying in 2s
    WARN[2024-06-21T10:42:53.582637715Z] Unable to locate plugin: my-driver, retrying in 4s

With this patch:

    dockerd --experimental -s my-driver
    ...
    INFO[2024-06-21T10:32:35.123078845Z] [graphdriver] trying configured driver: my-driver
    ERRO[2024-06-21T10:32:35.123127012Z] Failed to GetDriver graph                     driver=my-driver error="DEPRECATED: Experimental graphdriver plugins are deprecated, and disabled by default. This feature will be removed in the next release. See https://docs.docker.com/go/deprecated/" home-dir=/var/lib/docker
    INFO[2024-06-21T10:32:35.124735595Z] stopping healthcheck following graceful shutdown  module=libcontainerd
    INFO[2024-06-21T10:32:35.124743137Z] stopping event stream following graceful shutdown  error="context canceled" module=libcontainerd namespace=plugins.moby
    failed to start daemon: error initializing graphdriver: driver not supported: my-driver

With the `DOCKERD_DEPRECATED_GRAPHDRIVER_PLUGINS` env-var set:

    DOCKERD_DEPRECATED_GRAPHDRIVER_PLUGINS=1 dockerd --experimental -s my-driver
    ...
    INFO[2024-06-21T10:35:04.149901970Z] containerd successfully booted in 0.013614s
    INFO[2024-06-21T10:35:05.148195845Z] [graphdriver] trying configured driver: my-driver
    WARN[2024-06-21T10:35:05.150647679Z] Unable to locate plugin: my-driver, retrying in 1s
    WARN[2024-06-21T10:35:06.152531221Z] Unable to locate plugin: my-driver, retrying in 2s
    WARN[2024-06-21T10:35:08.158452389Z] Unable to locate plugin: my-driver, retrying in 4s
    WARN[2024-06-21T10:35:12.163699293Z] Unable to locate plugin: my-driver, retrying in 8s

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-21 13:08:31 +02:00
Paweł Gronowski
81b2027979 Merge pull request #48049 from thaJeztah/fix_swagger_tmpfsopts
api: swagger: fix definition of TmpFsOptions (API v1.46)
2024-06-21 12:22:26 +02:00
Paweł Gronowski
97f6a9d005 Merge pull request #48045 from thaJeztah/bump_ttrpc_1.2.5
vendor: github.com/containerd/ttrpc v1.2.5
2024-06-21 12:19:51 +02:00
Paweł Gronowski
3aace758b9 Merge pull request #48046 from thaJeztah/daemon_no_logrus
cmd/dockerd: initMiddlewares: use containerd/logs
2024-06-21 12:19:31 +02:00
Sebastiaan van Stijn
ce5571f343 api: swagger: fix definition of TmpFsOptions (API v1.46)
Since it's a [][]string, there should only be two levels of array
in the OpenAPI spec. Also, the outermost level array shouldn't have
properties: (it should have items: instead).

Co-authored-by: Mark Yen <mark.yen@suse.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-21 09:17:57 +02:00
Sebastiaan van Stijn
a9ab04603e cmd/dockerd: initMiddlewares: use containerd/logs
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-20 23:06:40 +02:00
Tianon Gravi
418eed6e4e Merge pull request #47804 from cpuguy83/more_paths_docker_proxy
Lookup docker-proxy in libexec paths
2024-06-20 13:52:21 -07:00
Sebastiaan van Stijn
e355e10011 vendor: github.com/containerd/ttrpc v1.2.5
full diff: https://github.com/containerd/ttrpc/compare/v1.2.4...v1.2.5

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-20 22:52:19 +02:00
Brian Goff
f8c088be05 Lookup docker-proxy in libexec paths
This allows distros to put docker-proxy under libexec paths as is done
for docker-init.

Also expands the lookup to to not require a `docker/` subdir in libexec
subdir.
Since it is a generic helper that may be used for something else in the
future, this is only done for binaries with a `docker-`.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2024-06-20 19:26:54 +00:00
Paweł Gronowski
018d93decf Merge pull request #47961 from gtomitsuka/gabriel/data-races
client: Make version negotiation thread-safe
2024-06-20 13:55:10 +02:00
Albin Kerouanton
1a1f3cff45 Merge pull request #48011 from thaJeztah/deprecate_runconfig_IsPreDefinedNetwork
runconfig: deprecate IsPreDefinedNetwork
2024-06-20 12:59:08 +02:00
Sebastiaan van Stijn
202de333a4 Merge pull request #48040 from thaJeztah/move_stats
api/types: move stats-types to api/types/container
2024-06-20 11:30:31 +02:00
Sebastiaan van Stijn
d22d8a78f1 runconfig: deprecate IsPreDefinedNetwork
Move the function internal to the daemon, where it's used. Deliberately
not mentioning the new location, as this function should not be used
externally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-20 11:10:54 +02:00
Sebastiaan van Stijn
a24af26aba Merge pull request #48037 from thaJeztah/registry_cleanups
registry: minor cleanups
2024-06-20 10:27:16 +02:00
Sebastiaan van Stijn
b5d3c47a37 Merge pull request #48033 from thaJeztah/api_update_examples
docs/api: update some example values to be more accurate (API v1.46)
2024-06-20 10:26:52 +02:00
Sebastiaan van Stijn
0a4277abf4 api/types: move stats-types to api/types/container
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-20 10:21:42 +02:00
Paweł Gronowski
fe60fa241b Merge pull request #48039 from thaJeztah/fixo_typo
api/types: fix typo in GoDoc
2024-06-20 10:15:35 +02:00
Paweł Gronowski
5ace798cab Merge pull request #48041 from thaJeztah/rename_statsresponse
api/types: rename container.StatsResponse to StatsResponseReader
2024-06-20 10:12:17 +02:00
Sebastiaan van Stijn
91a2a574d7 api/types: rename container.StatsResponse to StatsResponseReader
commit 17c3269a37 moved the ContainerStats
type to the container package, and renamed it to StatsResponse. However,
this name is chosen poorly, as it documents it to be the response of
the API endpoint, but is more accurately a wrapper around a reader,
used to read a (stream of) StatsJSON. We want to change StatsJSON
to StatsResponse, as it's more consistent with other response types.

As 17c3269a37 did not make it into a
non-pre-release, we can still change this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-20 08:54:52 +02:00
Akihiro Suda
485e1c7be7 Merge pull request #48035 from thaJeztah/more_mailmap
update one more entry in mailmap and AUTHORS
2024-06-20 09:16:16 +09:00
Sebastiaan van Stijn
6fafc8762f api/types: fix typo in GoDoc
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-20 01:39:32 +02:00
Brian Goff
3a36cad0bd Merge pull request #48034 from cyphar/volume-atomic-write
volume: use AtomicWriteFile to save volume options
2024-06-19 18:39:49 +00:00
Sebastiaan van Stijn
42cb29f6ea registry: Search.searchUnfiltered: inline variable
The scopes variable was used in one location; inline it where it's used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-19 17:05:48 +02:00
Sebastiaan van Stijn
43d4a4c63e registry: v2AuthHTTPClient: inline some vars and slight refactor
- inline the auth.TokenHandlerOptions in the auth.NewTokenHandlerWithOptions call
- construct a authHandlers slice to make it more clear that this is a variadic
  list of authentication-handlers.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-19 17:04:59 +02:00
Sebastiaan van Stijn
bf35f3d8c8 update one more entry in mailmap and AUTHORS
Found back the PR related to this contributors, and they addressed
their name in an intermediate rebase, but it got lost in a later one.

While at it, also fixed an entry next to it :)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-19 12:48:41 +02:00
Aleksa Sarai
b4c20da143 volume: use AtomicWriteFile to save volume options
If the system (or Docker) crashes while saivng the volume options, on
restart the daemon will error out when trying to read the options file
because it doesn't contain valid JSON.

In such a crash scenario, the new volume will be treated as though it
has the default options configuration. This is not ideal, but volumes
created on very old Docker versions (pre-1.11[1], circa 2016) do not
have opts.json and so doing some kind of cleanup when loading the volume
store (even if we take care to only delete empty volumes) could delete
existing volumes carried over from very old Docker versions that users
would not expect to disappear.

Ultimately, if a user creates a volume and the system crashes, a volume
that has the wrong config is better than Docker not being able to start.

[1]: commit b05b237075 ("Support mount opts for `local` volume driver")

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2024-06-19 18:57:51 +10:00
Akihiro Suda
11179de64c Merge pull request #48031 from thaJeztah/bump_cobra
vendor: github.com/spf13/cobra v1.8.1
2024-06-19 14:19:41 +09:00
Akihiro Suda
9e85d1cb41 Merge pull request #48032 from thaJeztah/update_mailmap
update .mailmap and AUTHORS
2024-06-19 14:19:09 +09:00
Sebastiaan van Stijn
39b4448e12 docs/api: update some example values to be more accurate (API v1.46)
Update daemon versions, and minimum supported API version to be more
representative to what the API would return.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-19 00:51:14 +02:00
Sebastiaan van Stijn
37b57c2ae0 api: swagger: update some example values to be more accurate
Update daemon versions, and minimum supported API version to be more
representative to what the API would return.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-19 00:50:23 +02:00
Sebastiaan van Stijn
2a7bb2a7bd update .mailmap and AUTHORS
I noticed some duplicates made their way in, in
084219a5f9 and some authors
didn't have git configured properly to include the name
they used for the sign-off

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 23:31:38 +02:00
Sebastiaan van Stijn
e7347f8a8c Merge pull request #48030 from thaJeztah/bump_buildx
Dockerfile: update buildx to v0.15.1
2024-06-18 22:59:07 +02:00
Sebastiaan van Stijn
68b8e97849 vendor: github.com/spf13/cobra v1.8.1
- release notes: https://github.com/spf13/cobra/releases/tag/v1.8.1
- full diff: https://github.com/spf13/cobra/compare/v1.8.0...v1.8.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 22:17:41 +02:00
Sebastiaan van Stijn
b5cc61a243 Dockerfile: update buildx to v0.15.1
This is the version used in the dev-container, and for testing.

release notes:
https://github.com/docker/buildx/releases/tag/v0.15.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 21:36:25 +02:00
Sebastiaan van Stijn
59b119f94e Merge pull request #47994 from thaJeztah/simplify_getDummyName
libnetwork: ipvlan, macvlan: cleanup getDummyName utility
2024-06-18 21:25:55 +02:00
Albin Kerouanton
3e85c9d517 Merge pull request #48025 from robmry/fix_port_mapped_hairpin
Fix hairpin between networks with mapped port
2024-06-18 19:46:16 +02:00
Sebastiaan van Stijn
f741ca857c libnetwork/drivers/macvlan: getDummyName don't use stringid.TruncateID
The stringid.TruncateID utility is used to provide a consistent length
for "short IDs" (containers, networks). While the dummy interfaces need
a short identifier, they use their own format and don't have to follow
the same length as is used for "short IDs" elsewhere.

In addition, stringid.TruncateID has an additional check for the given
ID to contain colons (":"), which won't be the case for network-IDs that
are passed to it, so this check is redundant.

This patch moves the truncating local to the getDummyName function, so
that it can define its own semantics, independent of changes elsewhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 19:40:15 +02:00
Sebastiaan van Stijn
d241862f36 libnetwork/drivers/macvlan: move truncating ID to getDummyName
The function description mentions that the returned value will contain
a truncated ID, but the function was only prepending the prefix, which
meant that callers had to be aware that truncating is necessary.

This patch moves truncating the ID into the utility to make its use
less error-prone, and to make the code a bite more DRY.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 19:40:12 +02:00
Sebastiaan van Stijn
dab918b2b0 libnetwork/drivers/ipvlan: getDummyName don't use stringid.TruncateID
The stringid.TruncateID utility is used to provide a consistent length
for "short IDs" (containers, networks). While the dummy interfaces need
a short identifier, they use their own format and don't have to follow
the same length as is used for "short IDs" elsewhere.

In addition, stringid.TruncateID has an additional check for the given
ID to contain colons (":"), which won't be the case for network-IDs that
are passed to it, so this check is redundant.

This patch moves the truncating local to the getDummyName function, so
that it can define its own semantics, independent of changes elsewhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 19:34:25 +02:00
Sebastiaan van Stijn
b8c80b19de libnetwork/drivers/ipvlan: move truncating ID to getDummyName
The function description mentions that the returned value will contain
a truncated ID, but the function was only prepending the prefix, which
meant that callers had to be aware that truncating is necessary.

This patch moves truncating the ID into the utility to make its use
less error-prone, and to make the code a bite more DRY.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 19:34:23 +02:00
Albin Kerouanton
fb8d8a9fe5 Merge pull request #47318 from andrewbaxter/47317-allow-macvlan-dup-parent
Allow multiple macvlan networks to share a parent
2024-06-18 19:32:24 +02:00
Sebastiaan van Stijn
b5b7ddfdd5 Merge pull request #48028 from tonistiigi/update-buildkit-v0.14.1
vendor: update buildkit to v0.14.1
2024-06-18 19:12:51 +02:00
Tonis Tiigi
8599213b52 vendor: update buildkit to v0.14.1
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-18 09:12:55 -07:00
Rob Murray
2df4391473 Fix hairpin between networks with mapped port
Following changes to the port mapping code, the DNAT iptables rule was
inserted into the nat table rather than appended.

This meant DNAT was applied before the rule that should have skipped
it when a packet was from a bridge network.

So, packets sent from a container on one network to a mapped port on
the host's address were DNAT'd before docker-proxy could pick them up,
then they were dropped by a rule intended to isolate the networks.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-18 16:14:16 +01:00
Sebastiaan van Stijn
fd71cbfab5 Merge pull request #48026 from thaJeztah/api_v1.46_docs
docs: add API documentation for API v1.46
2024-06-18 15:28:03 +02:00
Sebastiaan van Stijn
9402ea1c8e Merge pull request #48023 from thaJeztah/local_ulimits_alias
api/types/container: provide alias for github.com/docker/go-units.Ulimit
2024-06-18 14:19:43 +02:00
Sebastiaan van Stijn
b06b6b3648 docs: add API documentation for API v1.46
This is the API version to be released with v27.0, and the API
is now frozen for this release, so we can create the documentation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 14:15:13 +02:00
Sebastiaan van Stijn
f174059a25 Merge pull request #48019 from thaJeztah/executor_err_handling
daemon/cluster/executor/container: fix error-handling
2024-06-18 14:13:46 +02:00
Paweł Gronowski
ea48d90399 Merge pull request #48024 from vvoland/update-authors
update AUTHORS
2024-06-18 14:13:14 +02:00
Sebastiaan van Stijn
5a4595466b Merge pull request #48008 from thaJeztah/deprecate_runconfig_DefaultDaemonNetworkMode
runconfig: deprecate DefaultDaemonNetworkMode, move to daemon/network
2024-06-18 14:13:07 +02:00
Sebastiaan van Stijn
f160cd0087 Merge pull request #48016 from thaJeztah/deprecate_runconfig_opts
runconfig/opts: deprecate ConvertKVStringsToMap and move internal
2024-06-18 14:10:58 +02:00
Sebastiaan van Stijn
517fb0991e api/types/container: provide alias for github.com/docker/go-units.Ulimit
This type is included in various types used in the API, but comes from
a separate module. The go-units module may be moving to the moby org,
and it is yet to be decided if the Ulimit type is a good fit for that
module (which deals with more generic units, such as "size" and "duration"
otherwise).

This patch introduces an alias to help during the transition of this type
to it's new location. The alias makes sure that existing code continues
to work (at least for now), but we need to start updating such code after
this PR is merged.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 13:18:20 +02:00
Sebastiaan van Stijn
c3217300e2 Merge pull request #48022 from thaJeztah/leftover_nits
daemon, daemon/cluster, integration/container: minor linting issues and cleanups
2024-06-18 13:17:41 +02:00
Sebastiaan van Stijn
ad716b223b integration/container: use consistent alias for import
The canonical alias is "containertypes" for this import.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 13:11:37 +02:00
Sebastiaan van Stijn
25f44885ed daemon/cluster/executor/container: use consistent alias for import
The canonical alias is "containertypes" for this import.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 13:11:34 +02:00
Paweł Gronowski
084219a5f9 update AUTHORS
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-18 13:01:11 +02:00
Sebastiaan van Stijn
f09f756851 daemon/cluster: minor linting issues and cleanup
- rename variables that shadowed imports
- remove some intermediate vars
- slight reformating for readability

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 10:42:56 +02:00
Rob Murray
9e389b1eac Merge pull request #48020 from robmry/revert_internal_resolver_for_default_bridge
Revert internal resolver for default bridge
2024-06-18 09:04:57 +01:00
Sebastiaan van Stijn
4ea464d1a7 Merge pull request #47950 from psaintlaurent/ENGINE-903
Add OOMScoreAdj to the moby API
2024-06-17 22:58:24 +02:00
Rob Murray
74d77d8811 Revert "Internal resolver for default bridge network"
This reverts commit 18f4f775ed.

Because buildkit doesn't run an internal resolver, and it bases its
/etc/resolv.conf on the host's ... when buildkit is run in a container
that has 'nameserver 127.0.0.11', its build containers will use Google's
DNS servers as a fallback (unless the build container uses host
networking).

Before, when the 127.0.0.11 resolver was not used for the default network,
the buildkit container would have inherited a site-local nameserver. So,
the build containers it created would also have inherited that DNS
server - and they'd be able to resolve site-local hostnames.

By replacing the site-local nameserver with Google's, we broke access
to local DNS and its hostnames.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-17 20:19:20 +01:00
Rob Murray
6d35673504 Revert "No default nameservers for internal resolver"
This reverts commit d365702dbd.

Because buildkit doesn't run an internal resolver, and it bases its
/etc/resolv.conf on the host's ... when buildkit is run in a container
that has 'nameserver 127.0.0.11', its build containers will use Google's
DNS servers as a fallback (unless the build container uses host
networking).

Before, when the 127.0.0.11 resolver was not used for the default network,
the buildkit container would have inherited a site-local nameserver. So,
the build containers it created would also have inherited that DNS
server - and they'd be able to resolve site-local hostnames.

By replacing the site-local nameserver with Google's, we broke access
to local DNS and its hostnames.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-17 20:19:10 +01:00
Sebastiaan van Stijn
01efb9a5ab daemon/cluster/executor/container: fix error-handling
While working on this file, I noticed the `isContainerCreateNameConflict`,
`isUnknownContainer`, and `isStoppedContainer` utilities, which are used
to perform error-type detection through string-matching.

These utilities were added in 534a90a993,
as part of the initial implementation of the Swarm executor in Docker.
At that time, the Docker API client did not return typed errors, and
various part of the code depended on string matching, which is brittle,
and it looks like `isContainerCreateNameConflict` at least is already
broken since c9d0a77657, which changed
the error-message.

Starting with ebcb7d6b40, we use typed
errors through the errdefs package, so we can replace these utilities:

The `isUnknownContainer` utility is replace by `errdefs.IsNotFound`,
which is returned if the object is not found. Interestingly, this utility
was checking for containers only (`No such container`), but was also
used for an `removeNetworks` call. Tracking back history of that use to
verify if it was _intentionally_ checking for a "container not found"
error;

- This check added in the initial implementation 534a90a993
- Moved from `controller.Remove` to `container.Shutdown` to make sure the
  sandbox was removed in 680d0ba4ab
- And finally touched again in 70fa7b6a3f,
  which was a follow-up to the previous one, and fixed the conditions
  to prevent returning early before the network was removed.

None of those patches mention that these errors are related to containers,
and checking the codepath that's executed, we can only expect a
`libmetwork.ErrNoSuchNetwork` to be returned, so this looks to have been
a bug.

The `isStoppedContainer` utility is replaced by `errdefs.IsNotModified`,
which is the error (status) returned in situations where the container
is already stopped; caf502a0bc/daemon/stop.go (L30-L35)
This is the only

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 21:14:47 +02:00
plaurent
b640582436 Add OomScoreAdj options
Signed-off-by: plaurent <patrick@saint-laurent.us>
2024-06-17 12:01:06 -04:00
Sebastiaan van Stijn
8e91b64e07 runconfig: deprecate DefaultDaemonNetworkMode, move to daemon/network
This function returns the default network to use for the daemon platform;
moving this to a location separate from runconfig, which is planned to
be dismantled and moved to the API.

While it might be convenient to move this utility inside api/types/container,
we don't want to advertise this function too widely, as the default returned
can ONLY be considered correct when ran on the daemon-side. An alternative
would be to introduce an argument (daemonPlatform), which isn't very convenient
to use.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 17:32:56 +02:00
Paweł Gronowski
caf502a0bc Merge pull request #47239 from cpuguy83/containerd_image_info
Set containerd container image ref
2024-06-17 17:02:24 +02:00
Sebastiaan van Stijn
d88ae86a16 Merge pull request #48014 from thaJeztah/daemon_rename_imports
daemon: rename some inconsistent import aliases
2024-06-17 16:40:53 +02:00
Paweł Gronowski
9f4cd92e07 Merge pull request #47929 from vvoland/image-create
daemon: Emit Image Create event when image is built
2024-06-17 16:30:35 +02:00
Sebastiaan van Stijn
437e1ae15e runconfig/opts: deprecate ConvertKVStringsToMap and move internal
This utility is only used in two places, and simple enough to duplicate.
There's no external consumers, and a copy of this utility exists in docker/cli
for use on the client side, so we could consider skipping deprecation,
but just to be on the safe side ':)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 16:23:39 +02:00
Sebastiaan van Stijn
b3e236d3b5 daemon: rename some inconsistent import aliases
These used aliases that weren't used elsewhere, so renaming / removing
to keep some consistency. Some local variables were renamed to prevent
shadowing.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 14:50:09 +02:00
Brian Goff
2851ddc44c Add containerd image ref to created containers
This populates the "Image" field on containerd containers, but only when
using the containerd image store.
This allows containerd clients to look up the image information.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 14:45:17 +02:00
Brian Goff
812f319a57 Add containerd connection info to info endpoint (API v1.46)
This will be used in the next commit to test that changes are propagated
to the containerd store.
It is also just generally useful for debugging purposes.

- docs/api: update version history
- daemon: add fillContainerdInfo utility
- api: update swagger file with new types

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 14:43:39 +02:00
Paweł Gronowski
1327342b14 hack: Ignore deprecate-integration-cli validation
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-17 14:05:15 +02:00
Paweł Gronowski
7b8f4922a5 daemon: Emit Image Create event when image is built
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-17 14:05:12 +02:00
Paweł Gronowski
09eb6ec4f1 builder/exporter: Wrap exporter to hook the image export
Buildkit doesn't call the engine API when it builds an image without
tag. Wrap the exporter returned by the worker that calls a callback when
a new image is exported from buildkit.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-17 14:05:11 +02:00
Paweł Gronowski
0e84482ef5 builder-next: Move exporter wrapper to exporter package
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-17 14:05:09 +02:00
Sebastiaan van Stijn
eb360efeb5 Merge pull request #48013 from thaJeztah/reformat_networkmodes
api/types/container: reformat to align windows and unix implementations
2024-06-17 13:20:56 +02:00
Sebastiaan van Stijn
7012c4a129 Merge pull request #47996 from thaJeztah/pkg_longpath_deprecate_Prefix
pkg/longpath: deprecate Prefix const, and use early returns in AddPrefix
2024-06-17 13:18:33 +02:00
Sebastiaan van Stijn
b2441c7419 Merge pull request #45052 from cpuguy83/attach_fd_leak
Fix attach goroutine/fd leak when no I/O is ready
2024-06-17 13:16:08 +02:00
Sebastiaan van Stijn
08aebce331 Merge pull request #48012 from thaJeztah/daemon_less_shadow
daemon: rename variables that shadowed imports
2024-06-17 12:59:09 +02:00
Sebastiaan van Stijn
53c521bdc9 Merge pull request #47993 from thaJeztah/builder_dockerfile_cleanups
builder/dockerfile: assorted linting fixes, and remove LCOW leftover
2024-06-17 12:06:25 +02:00
Sebastiaan van Stijn
48ff86ec64 pkg/longpath: AddPrefix: use early returns
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 12:04:26 +02:00
Sebastiaan van Stijn
424c22390e pkg/longpath: deprecate Prefix const
This const was exported because it was in use by pkg/symlink. This
dependency was removed in a48c6e3005,
after which this const was only used internally.

This patch deprecates the const and introduces a non-exported const
to use.

There are no known external consumers of this const, so we may skip
deprecating it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 12:03:27 +02:00
Sebastiaan van Stijn
2f45cbf69f api/types/container: NetworkMode align code between Windows and Linux
Change the order of declarations betwen both implementations for easier
comparing of differences.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 11:53:19 +02:00
Sebastiaan van Stijn
7b56fa8dc0 api/types/container: NetworkMode.NetworkName: use switch
- Use a switch instead of if/else for readability and to reduce
  the risk of duplicates in the checks.
- Align order between Windows and Linux implementation for easier
  comparing of differences in the implementation.
- Add a check for `IsHost()` in the Windows implementation which
  would never occur currently, but is implemented.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 11:49:37 +02:00
Sebastiaan van Stijn
680e6d6e1c Merge pull request #48000 from thaJeztah/nosec_comments
pkg/archive. pkg/tarsum: format #nosec comments to standard format
2024-06-17 11:46:25 +02:00
Sebastiaan van Stijn
c114b5e6f0 Merge pull request #47997 from thaJeztah/pkg_archive_no_longpath
pkg/archive, pkg/chrootarchive: remove dependency on pkg/longpath
2024-06-17 11:43:59 +02:00
Sebastiaan van Stijn
4014b893e4 Merge pull request #48007 from thaJeztah/runconfig_drop_old_api_versions
runconfig: remove code for API < v1.18, deprecate SetDefaultNetModeIfBlank, ContainerConfigWrapper
2024-06-17 11:43:15 +02:00
Sebastiaan van Stijn
9c7f20e255 Merge pull request #48003 from thaJeztah/pkg_archive_cleanup
pkg/archive: assorted minor refactors and cleanups
2024-06-17 11:11:42 +02:00
Sebastiaan van Stijn
7b438c5c31 daemon: rename variables that shadowed imports
Not a full list yet, but renaming to prevent shadowing, and to use a more
consistent short form (ctr for container).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 11:06:06 +02:00
Sebastiaan van Stijn
21a7686862 Merge pull request #47995 from thaJeztah/stringid_cleanups
pkg/stringid: deprecate ValidateID, IsShortID
2024-06-17 10:55:06 +02:00
Sebastiaan van Stijn
e788628e2e Merge pull request #48005 from thaJeztah/pkg_archive_rm_kernelversion_check
pkg/archive: TestChangesDirsEmpty, TestChangesDirsMutated: no kernel-version check
2024-06-17 10:34:36 +02:00
Albin Kerouanton
a5fede8a51 Merge pull request #48006 from thaJeztah/libnetwork_nosversion
libnetwork: remove special handling for Windows 14393 (RS1, V1607, LTSC2016)
2024-06-17 10:25:28 +02:00
Sebastiaan van Stijn
4c7228663c api/server/router/container.postCommit: add TODO about use of CreateRequest
The commit endpoint accepts a container.Config, but uses the decoder to
unmarshal the request. The decoder uses a CreateRequest, which is a superset,
and also contains HostConfig and network.NetworkConfig. Those structs are
discarded in the router, but decoder.DecodeConfig also performs validation,
so a request containing those additional fields would result in a validation
error.

We should rewrite this code to only unmarshal what's expected.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 00:26:46 +02:00
Sebastiaan van Stijn
c692af36c3 runconfig: deprecate ContainerConfigWrapper, move to api/types/container
Move the type to api/types/container.CreateRequest, together with other
types used by the container API endpoints.

The Decoder, and related validation code is kept in the runconfig package
for now, but should likely be moved elsewhere (inside the API).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 00:26:46 +02:00
Sebastiaan van Stijn
afdfe4ff86 runconfig: deprecate SetDefaultNetModeIfBlank
Remove uses of this function and mark it deprecated. There's no known
consumers of this function, but let's stay on the safe side, and mark
it deprected for 1 release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 00:26:46 +02:00
Sebastiaan van Stijn
4af9f418a3 runconfig: remove ContainerConfigWrapper.getHostConfig() utility
This utility used to be responsible for backward compatibility with old
API versions, but was reduced to a single line. Inline the code, and
inline the SetDefaultNetModeIfBlank code, which in itself also was
just 3 lines of code.

A platform check was added to only set the default network conditionally,
but other paths in the codebase don't perform this conditionally, so a
TODO was added, to verify if this behavior is needed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 00:26:46 +02:00
Sebastiaan van Stijn
98bd08c534 runconfig: remove redundant import-alias
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 00:26:46 +02:00
Sebastiaan van Stijn
e42503213d runconfig: ContainerConfigWrapper: unify Linux and Windows implementations
Now that the backward-compatibility code has been removed, the Linux and
Windows implementations of this struct are identical, so the platform-
specific code can be removed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 00:26:45 +02:00
Sebastiaan van Stijn
2954b05b03 runconfig: remove conversion code for API < v1.18
The runconfig package contained compatibility code to unmarshal API
requests on API < v1.18, and to convert them to current API versions.
These fields were marked as deprecated, but didn't mention relevant API
versions, so some digging was needed to track back history;

API versions before 1.18 accepted top-level `Memory`, `MemorySwap`,
`CpuShares`, and `Cpuset` fields as part of the container create requests.
These fields were not considered "portable", and therefore moved to the
`HostConfig` struct in 837eec064d. The
API version at that time was [v1.18]. For backward-compatibility, the
existing top-level fields were kept, and conversion code was added in
[ContainerHostConfigFromJob] to copy their values to `HostConfig` if
present.

A refactor in 767df67e31 introduced a new
`ContainerConfigWrapper` struct, which embedded the container-config and
a (non-exported) `hostConfigWrapper`. This resulted in an incompatibility
when compiling with gccgo, sn eb97de7dee
removed the non-exported `hostConfigWrapper`, instead embedding the
`HostConfig` and adding a `CpuSet` field. The API version at that time
was [v1.19].

With the introduction of Windows containers, which did not need conversion
code as it never supported previous API versions, the `ContainerConfigWrapper`
was split to Linux and Windows implementation in f6ed590596.
This change introduced a `SetDefaultNetModeIfBlank` function to set the
default network-mode on Linux. Windows did not have a default network,
but did require a separate `ValidateNetMode` implemenation.

The `ContainerConfigWrapper` was expanded to include `NetworkingConfig`
in 2bb3fc1bc5 for API [v1.22], but did
not involve backward-compatiblity / conversion code.

Based on the above, all conversion code present in runconfig is related
to API versions [v1.18] or before. 19a04efa2f,
and other commits in [moby PR 47155] removed support for API < v1.24, so
this conversion code is no longer needed.

This patch removes the legacy fields from the `ContainerConfigWrapper`,
and removes the corresponding conversion code. The `InnerHostConfig` field
is also renamed, as it is no longer shadowed by the `container.HostConfig`
that was embedded for backward-compatibility.

[v1.18]: 837eec064d/api/common.go (L18)
[v1.19]: 767df67e31/api/common.go (L20)
[v1.22]: 2bb3fc1bc5/api/common.go (L21)
[moby PR 47155]: https://github.com/moby/moby/pull/47155
[ContainerHostConfigFromJob]: 837eec064d/runconfig/hostconfig.go (L149-L162)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 00:26:45 +02:00
Sebastiaan van Stijn
37f4616751 integration-cli: fix TestCreateWithTooLowMemoryLimit: using deprecated API fields
This test was depending on top-level fields that were deprecated since
API v1.18. These fields are no longer sent by current clients.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-17 00:26:31 +02:00
Sebastiaan van Stijn
964aba696c libnetwork: windows/overlay: remove endpointRequest wrapper
This wrapper is now a plain alias for hcsshim.HNSEndpointRequest, so let's
remove the extra abstraction.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 19:02:18 +02:00
Sebastiaan van Stijn
c316ed0c22 libnetwork: remove special handling for Windows 14393 (RS1, V1607, LTSC2016)
This synchronisation was added in [libnetwork@0a61693]:

> Adding synchronization around peerAdd and peerDelete to prevent network
> connectivity issue
>
> When multiple networks are present in a Swarm Cluster, multiple peerAdd
> or peerDelete calls are an issue for different remote endpoints. These
> threads are updating the remote endpoint to HNS parallelly. In 2016 HNS
> code base, we don't have synchronization around remoteEndpoint addition
> and deletion. So serializing the peerAdd and peerDelete calls from docker
> network driver.

We no longer support and test Windows 2016, as it reached EOL / end of
[standard support][1], so we can remove this special condition.

[libnetwork@0a61693]: c90114ce7c
[1]: https://en.wikipedia.org/wiki/Windows_10,_version_1607

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 18:59:21 +02:00
Akihiro Suda
ec4bac431c Merge pull request #47999 from thaJeztah/deprecate_pkg_dmesg
pkg/dmesg: deprecate, and use internal utility instead
2024-06-17 01:50:53 +09:00
Akihiro Suda
ff652c82e9 Merge pull request #48001 from thaJeztah/pkg_archive_deprecate_CanonicalTarNameForPath
pkg/archive: deprecate CanonicalTarNameForPath
2024-06-17 01:50:21 +09:00
Akihiro Suda
19257effaa Merge pull request #48002 from thaJeztah/pkg_archive_deprecate_TempArchive
pkg/archive: deprecate NewTempArchive, TempArchive
2024-06-17 01:49:58 +09:00
Sebastiaan van Stijn
3108165c94 pkg/archive: TestChangesDirsEmpty, TestChangesDirsMutated: no kernel-version check
TestChangesDirsEmpty and TestChangesDirsMutated fail on Windows V19H1 (1903)
and up, possibly due to changes in the kernel:

    === FAIL: github.com/docker/docker/pkg/archive TestChangesDirsEmpty (0.21s)
    changes_test.go:261: Reported changes for identical dirs: [{\dirSymlink C}]

    === FAIL: github.com/docker/docker/pkg/archive TestChangesDirsMutated (0.14s)
    changes_test.go:391: unexpected change "C \\dirSymlink" "\\dirnew"

commit 8f4b3b0ad4 added a version-dependent
skip for those tests, but as we no longer run CI on versions before V19H1,
we can remove the kernel-version check, and skip it on Windows unconditionally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 18:40:50 +02:00
Sebastiaan van Stijn
17ca8b62bd pkg/archive: remove uses of iota
While using iota can be convenient, it can also make it harder to grasp
what value is assigned. Use of iota also makes changing values implicit;
changing the order of these consts implicitly means their value changes.

This can be problematic, as some of these consts are a plain `int` and
while golang is strong-typed, it does allow plain `int` values to be
used for such values.

For example, `archive.Tar` accepts a `Compression` as second argument,
but allows a plain int to be passed, so both of these are equivalent;

    archive.Tar(contextDir, archive.Uncompressed)
    archive.Tar(contextDir, 0)

This patch removes the use of `iota`, and instead explicitly setting a
value for each to prevent accidental changes in their value, which can
be hard to discover.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 17:14:49 +02:00
Sebastiaan van Stijn
94caeeb401 pkg/archive: don't call system.Lgetxattr on unsupported platforms
[pkg/system.Lgetxattr] is only implemented on Linux, and always produces
an ErrNotSupportedPlatform on other platforms.

This patch removes the call to this function, but intentionally leaves
it commented-out as a reminder to include this code if this would ever
be refactored and implemented on other platforms.

[pkg/system.Lgetxattr]: d1273b2b4a/pkg/system/xattrs_unsupported.go (L1-L8)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 17:14:49 +02:00
Sebastiaan van Stijn
c565a3a1fe pkg/archive: collectFileInfo: don't create FileInfo if unused
The system.Lstat may fail, in which case it would be discarded,
so let's move it later.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 17:14:49 +02:00
Sebastiaan van Stijn
7ce1edd7c6 pkg/archive: deprecate NewTempArchive, TempArchive
These were added in baacae8345, but are
currently only used in tests inside pkg/archive. There are no external
users of this function, so we should deprecated them.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 17:07:47 +02:00
Sebastiaan van Stijn
92b8d93f47 pkg/archive: deprecate CanonicalTarNameForPath
Commit d59758450b changed this function to
be a wrapper for `filepath.ToSlash`. It was used in the CLI for the classic
builder, but is no longer used in our codebase.

However, there may still be some consumers that copied the CLI code for the
classic builder that didn't synchronise their implementation yet, so let's
deprecate this function to give them a warning that they should no longer
use this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 16:56:25 +02:00
Sebastiaan van Stijn
0ffc0c95e6 pkg/tarsum: format #nosec comments to standard format
gosec uses a non-standard format for "automated" comments to suppress
false positives (such comments should not have a leading space, but
are not allowed to start with a non-alphabetical character). However,
current versions of gosec do allow a leading space.

This patch reformats the comments to prevent them from being changed
by IDEs when reformating code.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 14:31:27 +02:00
Sebastiaan van Stijn
cb19b59b65 pkg/archive: format #nosec comments to standard format
gosec uses a non-standard format for "automated" comments to suppress
false positives (such comments should not have a leading space, but
are not allowed to start with a non-alphabetical character). However,
current versions of gosec do allow a leading space.

This patch reformats the comments to prevent them from being changed
by IDEs when reformating code.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 14:31:18 +02:00
Sebastiaan van Stijn
805ccd2365 pkg/dmesg: deprecate, and use internal utility instead
This package was originally added in 46833ee1c3
for use in the devicemapper graphdriver. The devicemapper graphdriver was
deprecated and has been removed. The only remaining consumer is an integration
test.

Deprecate the package and mark it for removal in the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 12:41:39 +02:00
Sebastiaan van Stijn
c7f4abc14a pkg/dmesg: use unix.SYSLOG_ACTION_READ_ALL instead of local variable
This value was originally added in 46833ee1c3,
at which time golang.org/x/sys/unix didn't have utilities for this syscall.
A later patch switched the implementation to use the golang/x/sys/unix
implementation in 2841b05b71, but kept the
local variable.

golang.org/x/sys now has a const for this, so let's use it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-16 12:41:39 +02:00
Sebastiaan van Stijn
d1273b2b4a Merge pull request #46809 from dperny/add-exec-option-to-tmpfs
Rebase #36720 "Add exec option to tmpfs"
2024-06-15 22:32:59 +02:00
andrew
528ffa9cae Allow multiple macvlan networks to share a parent
The only case where macvlan interfaces are unable to share a parent is
when the macvlan mode is passthru. This change tightens the check to
that situation.

It also makes the error message more specific to avoid suggesting that
sharing parents is never correct.

Signed-off-by: Andrew Baxter <423qpsxzhh8k3h@s.rendaw.me>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 19:42:11 +02:00
Sebastiaan van Stijn
9389f76f6d pkg/chrootarchive: remove dependency on pkg/longpath
Copy the function to the package, so that we don't have a dependency
on pkg/longpath.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 17:32:08 +02:00
Sebastiaan van Stijn
f657a75bf6 pkg/archive: remove dependency on pkg/longpath
Copy the function to the package, so that we don't have a dependency
on pkg/longpath.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 17:30:13 +02:00
Sebastiaan van Stijn
2100a70741 pkg/stringid: deprecate IsShortID
This function is no longer used, and has no external users. Deprecated
the function and mark if for removal for the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 15:35:07 +02:00
Sebastiaan van Stijn
e19e6cf7f4 pkg/stringid: deprecate ValidateID
This function is only used for the legacy v1 image format.

Deprecate the function, and make image/v1 self-contained.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 15:34:38 +02:00
Sebastiaan van Stijn
0fb6360fa7 builder/dockerfile: createDestInfo: remove platform arg (LCOW left-over)
This was added in 7a7357dae1 as part of the
LCOW implementation. LCOW has been removed, and this option was no longer
in use because of that.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 14:03:01 +02:00
Sebastiaan van Stijn
c5d95fdb04 builder/dockerfile: fix some minor linting issues
- explicitly suppress some errors
- use fmt.Fprintln instead of manually appending a newline
- remove an outdated TODO; looking at the suggestion, it's not a
  realistic option

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 14:02:55 +02:00
Sebastiaan van Stijn
6fa6812c51 builder/dockerfile: rename vars that shadowed types and builtins
- imageMount was shadowing the imageMount type
- copy was shadowing the copy builtin
- container was shadowing the container import

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 14:01:46 +02:00
Sebastiaan van Stijn
074932966d builder/dockerfile: remove endsInSlash utility
It was only used in a single location, and other locations were shadowing
the function through local variables. As it's a one-liner, inlining the
code may be just as transparent.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-15 13:51:44 +02:00
Sebastiaan van Stijn
98fecb0d54 Merge pull request #47991 from corhere/healthcheck-startinterval-swarm
api: adjust health start interval on swarm update
2024-06-15 10:30:57 +02:00
Cory Snider
c8e7fcf91a api: adjust health start interval on swarm update
The health-check start interval added in API v1.44, and the start
interval option is ignored when creating a Swarm service using an older
API version. However, due to an oversight, the option is not ignored
when older API clients _update_ a Swarm service. Fix this oversight by
moving the adjustment code into the adjustForAPIVersion function used by
both the createService and updateService handler functions.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2024-06-14 18:05:55 -04:00
Paweł Gronowski
ba69bd9c1e Merge pull request #47984 from akerouanton/daemon-restore-clear-net-state
daemon: restore: clear net state for stopped containers
2024-06-14 21:36:52 +02:00
Arash Deshmeh
dd1ca95ef9 Add exec option to API TmpfsOptions
Includes two commits from Arash Deshmeh:

add exec option to API TmpfsOptions and the related volume functions

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>

feature: daemon handles tmpfs mounts exec option

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>

Updated by Drew Erny

Signed-off-by: Drew Erny <derny@mirantis.com>
2024-06-14 12:11:20 -05:00
Albin Kerouanton
c467e4f08d Merge pull request #47989 from robmry/ipv6_bridge_route_noerrlog
Don't log an error about route-add for IPv6 bridge
2024-06-14 18:50:20 +02:00
Albin Kerouanton
07053a0991 testutil/daemon: Wait() until the daemon is Kill()'ed
`Daemon.Kill()` was sending a SIGKILL to the daemon process but wasn't
waiting until the process was really killed. While the race window is
really small, better safe than sorry.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-14 18:35:31 +02:00
Albin Kerouanton
955b923352 daemon: releaseNetwork: clear SandboxID, SandboxKey
When the container stops or during `restore`, `daemon.releaseNetwork` is
used to clear all net-related state carried by a container. However, the
fields `SandboxID` and `SandboxKey` are never cleared. On the next start,
these fields will be replaced with new values. There's no point in
preserving these data since they became invalid as soon as the container
stopped.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-14 18:35:31 +02:00
Albin Kerouanton
e3c5665d21 daemon: restore: clear net state for stopped containers
When the daemon crashes, the host unexpectedly reboot, or the daemon
restarts with live-restore enabled, running containers might stop and the
on-disk state for containers might diverge from reality. All these
situations are currently handled by the daemon's `restore` method.

That method calls `daemon.Cleanup()` for all the dead containers. In
turn, `Cleanup` calls `daemon.releaseNetwork()`. However, this last
method won't do anything because it expects the `netController` to be
initialized when it's called. That's not the case in the `restore` code
path -- the `netController` is initialized _after_ cleaning up dead
containers.

There's a chicken-egg problem here, and fixing that would require some
important architectural changes (eg. change the way libnet's controller
is initialized).

Since `releaseNetwork()` early exits, dead containers won't ever have
their networking state cleaned. This led to bugs in Docker Desktop,
among other things.

Fix that by calling `releaseNetwork` after initializing the
`netController`.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-14 18:35:31 +02:00
Rob Murray
17a59a7506 Don't log an error about route-add for IPv6 bridge
setupBridgeIPv6 attempts to add a route to a new network while
the bridge device is 'down', so it always fails (and the route
is added anyway when the bridge is set 'up').

I'm almost sure the RouteAdd can be removed but, this close to
the moby 27.0 release, only sure-enough to demote the log message
from error to debug.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-14 16:34:23 +01:00
Paweł Gronowski
34c3569768 Merge pull request #47985 from vvoland/bk-patchimageconfig-panic
builder/mobyexporter: Add missing nil check
2024-06-14 17:05:21 +02:00
Albin Kerouanton
1882da852e Merge pull request #47906 from akerouanton/libnet-add-otel-spans-v3
api, daemon, libnet: Create OTel spans at various places
2024-06-14 17:03:56 +02:00
Albin Kerouanton
57c6a5e691 libnet: SetKey: propagate traces from API to SetKey reexec
The `Sandbox.SetKey()` method is called through an OCI prestart hook
which then calls back the daemon through a UNIX socket. This method is
responsible for provisioning interfaces, etc... into the sandbox.

A new EnvironCarrier is used to propagate the trace context to the
prestart hook, which then marhsals an OTel MapCarrier into the JSON
payload sent back to the daemon. That way, every spans created from
`SetKey()` are correctly parented to the original `ContainerStart` API
call.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-14 15:25:08 +02:00
Albin Kerouanton
b7186bdfc8 libnet: Sandbox: add ctx to SetKey
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-14 15:25:08 +02:00
Albin Kerouanton
6c71ebd82c libcontainerd: Start: add ctx
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-14 15:25:07 +02:00
Albin Kerouanton
2d8c4265c7 libcontainerd: NewTask: add ctx
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-14 15:25:07 +02:00
Albin Kerouanton
19f72d6fc4 libnet: add more OTel spans
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-14 15:25:07 +02:00
Albin Kerouanton
224d7291df container: add a span to CheckpointTo
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-14 15:25:07 +02:00
Paweł Gronowski
642242a26b builder/mobyexporter: Add missing nil check
Add a nil check to handle a case where the image config JSON would
deserialize into a nil map.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-14 15:25:04 +02:00
Sebastiaan van Stijn
076c976e28 Merge pull request #47981 from gtomitsuka/move-debug-to-dockerd
cli/debug: move to "cmd/dockerd/debug"
2024-06-14 09:53:34 +02:00
Gabriel Tomitsuka
44f19518f9 move the cli/debug package to cmd/dockerd/debug
Signed-off-by: Gabriel Tomitsuka <gabriel@tomitsuka.com>
2024-06-13 21:53:44 +00:00
Sebastiaan van Stijn
078c3a237c Merge pull request #47979 from thaJeztah/gofmt_builder
builder/builder-next: gofmt
2024-06-13 23:35:04 +02:00
Sebastiaan van Stijn
fef34669f6 Merge pull request #47976 from thaJeztah/bump_runc_1.1.13
update runc binary and vendor to v1.1.13
2024-06-13 23:06:31 +02:00
Sebastiaan van Stijn
e4e40558ba builder/builder-next: gofmt
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-13 21:50:12 +02:00
Gabriel Tomitsuka
88e5e4cfb4 Prevent data race during version negotiation
Signed-off-by: Gabriel Tomitsuka <gabriel@tomitsuka.com>
2024-06-13 19:37:11 +00:00
Sebastiaan van Stijn
9101392309 update runc binary to v1.1.13
Update the runc binary that's used in CI and for the static packages.

full diff: https://github.com/opencontainers/runc/compare/v1.1.12...v1.1.13

Release notes:

* If building with Go 1.22.x, make sure to use 1.22.4 or a later version.

* Support go 1.22.4+.
* runc list: fix race with runc delete.
* Fix set nofile rlimit error.
* libct/cg/fs: fix setting rt_period vs rt_runtime.
* Fix a debug msg for user ns in nsexec.
* script/*: fix gpg usage wrt keyboxd.
* CI fixes and misc backports.
* Fix codespell warnings.

* Silence security false positives from golang/net.
* libcontainer: allow containers to make apps think fips is enabled/disabled for testing.
* allow overriding VERSION value in Makefile.
* Vagrantfile.fedora: bump Fedora to 39.
* ci/cirrus: rm centos stream 8.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-13 21:25:10 +02:00
Sebastiaan van Stijn
ec24e19d69 vendor: github.com/opencontainers/runc v1.1.13
full diff: https://github.com/opencontainers/runc/compare/v1.1.12...v1.1.13

Release notes:

* If building with Go 1.22.x, make sure to use 1.22.4 or a later version.

* Support go 1.22.4+.
* runc list: fix race with runc delete.
* Fix set nofile rlimit error.
* libct/cg/fs: fix setting rt_period vs rt_runtime.
* Fix a debug msg for user ns in nsexec.
* script/*: fix gpg usage wrt keyboxd.
* CI fixes and misc backports.
* Fix codespell warnings.

* Silence security false positives from golang/net.
* libcontainer: allow containers to make apps think fips is enabled/disabled for testing.
* allow overriding VERSION value in Makefile.
* Vagrantfile.fedora: bump Fedora to 39.
* ci/cirrus: rm centos stream 8.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-13 21:25:06 +02:00
Sebastiaan van Stijn
ff5cc18482 Merge pull request #47977 from thaJeztah/bump_runc_deps
vendor: golang.org/x/sys v0.19.0, golang.org/x/crypto v0.22.0, golang.org/x/net v0.24.0
2024-06-13 21:11:12 +02:00
Sebastiaan van Stijn
7106a96be2 Merge pull request #47973 from thaJeztah/fix_gocompat
Add more go:build statements to prevent downgrading Go language version, and update to go1.21
2024-06-13 20:54:45 +02:00
Tianon Gravi
b5bc84119e Merge pull request #47960 from robmry/dev_container_ip6_tables
Dev container: try to load kernel module ip6_tables
2024-06-13 11:22:45 -07:00
Sebastiaan van Stijn
d20739b6fe vendor: golang.org/x/net v0.24.0
no changes in vendored files

full diff: https://github.com/golang/net/compare/v0.23.0...v0.24.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-13 17:48:51 +02:00
Sebastiaan van Stijn
535898dd9a vendor: golang.org/x/crypto v0.22.0
full diff: https://github.com/golang/crypto/compare/v0.21.0...v0.22.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-13 17:48:03 +02:00
Sebastiaan van Stijn
4b2aa9f875 vendor: golang.org/x/sys v0.19.0
full diff: https://github.com/golang/sys/compare/v0.18.0...v0.19.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-13 17:47:00 +02:00
Albin Kerouanton
cec0d50361 libnet: add ctx to Sandbox.Destroy()
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-13 17:13:43 +02:00
Albin Kerouanton
af23a024a1 libnet: Endpoint: add ctx to Join and Leave
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-13 17:00:05 +02:00
Albin Kerouanton
566026af8f libnet: Controller: add ctx to store methods
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-13 16:59:05 +02:00
Albin Kerouanton
9391052700 libnet: Add ctx to NewSandbox
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-13 16:52:48 +02:00
Albin Kerouanton
4924f56e7b libnet/driverapi: Add ctx to ProgramExternalConnectivity
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-13 16:51:55 +02:00
Albin Kerouanton
c5c1d133ef libnet/driverapi: Add ctx to Join
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-13 16:45:54 +02:00
Albin Kerouanton
8dcded102e libnet: add OTel spans to CreateEndpoint
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-13 16:45:31 +02:00
Sebastiaan van Stijn
450f18d3ca Merge pull request #47971 from thaJeztah/vendor_no_gocompat
hack/vendor.sh: remove redundant  -compat 1.18
2024-06-13 15:13:18 +02:00
Sebastiaan van Stijn
cf376170ed Add more go:build statements to prevent downgrading Go language version
Looks like some packages fail in go module mode, because they require
recent Go versions:

    GO111MODULE=on go test -v
    # github.com/docker/docker/libnetwork/ipamutils
    ../../libnetwork/ipamutils/utils.go:46:9: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../libnetwork/ipamutils/utils.go:51:9: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    # github.com/docker/docker/libnetwork/portallocator
    ../../libnetwork/portallocator/portallocator.go:179:7: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    # github.com/docker/docker/libnetwork/netutils
    ../../libnetwork/netutils/utils_linux.go:66:14: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../libnetwork/netutils/utils_linux.go:75:2: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    # github.com/docker/docker/api/server/router/grpc
    ../../api/server/router/grpc/grpc.go:56:48: predeclared any requires go1.18 or later (-lang was set to go1.16; check go.mod)
    # github.com/docker/docker/container
    ../../container/view.go:335:47: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)

    # github.com/docker/docker/libnetwork/ipams/defaultipam
    ../../libnetwork/ipams/defaultipam/address_space.go:33:2: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../libnetwork/ipams/defaultipam/address_space.go:53:2: clear requires go1.21 or later (-lang was set to go1.16; check go.mod)
    ../../libnetwork/ipams/defaultipam/address_space.go:124:10: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../libnetwork/ipams/defaultipam/address_space.go:125:21: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../libnetwork/ipams/defaultipam/address_space.go:146:22: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../libnetwork/ipams/defaultipam/address_space.go:310:14: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../libnetwork/ipams/defaultipam/address_space.go:311:22: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    # github.com/docker/docker/libnetwork/drivers/bridge
    ../../libnetwork/drivers/bridge/port_mapping_linux.go:76:15: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../libnetwork/drivers/bridge/port_mapping_linux.go:201:2: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-13 14:59:54 +02:00
Sebastiaan van Stijn
b7d5a42168 Update go:build comments to go1.21
Match the minimum version that's specified on our vendor.mod.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-13 14:59:54 +02:00
Sebastiaan van Stijn
c0c0bed9ab Merge pull request #47970 from thaJeztah/replace_compatcontext
remove internal/compatcontext and use context instead
2024-06-13 14:43:29 +02:00
Sebastiaan van Stijn
5343c7b451 remove internal/compatcontext and use context instead
This internal package was added in f6e44bc0e8
to preserve compatibility with go1.20 and older. At the time, our vendor.mod
still had go1.18 as minimum version requirement (see [1]), which got updated to go1.20
in 16063c7456, and go1.21 in f90b03ee5d

The version of BuildKit we use already started using context.WithoutCancel,
without a fallback, so we no longer can provide compatibility with older
versions of Go, which makes our compatiblity package redundant.

This patch removes the package, and updates our code to use stdlib's context
instead.

[1]: f6e44bc0e8/vendor.mod (L7)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-13 13:29:39 +02:00
Sebastiaan van Stijn
13c3384303 hack/vendor.sh: remove redundant -compat 1.18
This was added to use a specific format for the vendor.mod/go.mod
file, but we should no longer need this, as go1.21 is now the
minimum.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-13 13:24:07 +02:00
Albin Kerouanton
f20fd3c8a0 golangci-lint: ignore ineffassign & staticcheck on ctx shadowing
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-13 11:29:35 +02:00
Rob Murray
52333f3a34 Merge pull request #47871 from robmry/portmapper_fixes_and_nonat
Portmapper improvements, and options to disable NAT
2024-06-13 09:12:53 +01:00
Rob Murray
09777ade5a Merge pull request #47963 from robmry/47773_remove_ipv6_disable_escape_hatch
Remove ipv6 disable escape hatch
2024-06-12 19:13:31 +01:00
Rob Murray
d0790fd03e Trivial tidying in osl.setIPv6()
- Removed unnecessary variable 'enable'.
- Replaced a couple of fmt's with string concatenation.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-12 16:53:15 +01:00
Rob Murray
b7f1036cd9 Remove the option to ignore failure to disable ipv6
26.1.1 added env var DOCKER_ALLOW_IPV6_ON_IPV4_INTERFACE to make it
possible to create an IPv4-only network, even with a read-only
"/proc/sys/net" that meant IPv6 could not be disabled on an
interface.

In 27.0 it's easier to enable IPv6, just '--ipv6' when creating the
network - in particular, there's no need to allocate a subnet, because
a unique-local prefix will be assigned by default).

So, this change removes the env-var workaround. Now, the workarounds
are to enable IPv6, mount "/proc/sys/net" read-write, disable IPv6
by default in OS configuration, or remove support for IPv6 from the
kernel.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-12 16:28:29 +01:00
Rob Murray
44d00e3b9b Dev container: try to load kernel module ip6_tables
On an nftables host, the ip6_tables kernel module may not be loaded,
but it needs to be for dockerd to run (with ip6tables now enabled by
default).

If ip6tables doesn't work, try the dind official image's trick for
loading the module using "ip link show".

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-12 14:34:20 +01:00
Sebastiaan van Stijn
4fec999c11 Merge pull request #47956 from thaJeztah/cleanup_getDefaultNetworkSettings
daemon: cleanup getDefaultNetworkSettings
2024-06-12 13:47:55 +02:00
Paweł Gronowski
bcd280a3ed Merge pull request #47959 from vvoland/buildkit-update
Dockerfile: update buildx to v0.15.0
2024-06-12 10:35:59 +02:00
Paweł Gronowski
d0a135772e Dockerfile: update buildx to v0.15.0
- 0.15.0 release notes: https://github.com/docker/buildx/releases/tag/v0.15.0

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-12 09:42:18 +02:00
Sebastiaan van Stijn
c6b12f72a0 Merge pull request #47954 from tonistiigi/update-buildkit-v0.14.0
vendor: update buildkit to v0.14.0
2024-06-11 23:46:56 +02:00
Sebastiaan van Stijn
215410316f daemon: cleanup getDefaultNetworkSettings
Small cleanup of this function;

- change to a regular function, as it does not depend on the daemon
- use an early return
- explicitly refer to EndpointSettings.EndpointSettings, not the top-
  level EndpointSettings.
- use a struct-literal.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-11 23:40:35 +02:00
Rob Murray
01eecb6cdf Validate port bindings for gateway_mode=routed
When bridge driver opt com.docker.network.bridge.gatway_mode_ipv[46]
is set to "routed", there is no NAT.

When there's no NAT, there's no meaning to the HostPort field in a
port mapping (all the port mapping does is open the container's port),
and the HostIP field is only used to determine the address family.

So, check port bindings, and raise errors if fields are unexpectedly
set when the mapping only applies to a gateway_mode=routed network.
Zero-addresses are allowed, to say the mapping/open-port should be
IPv4-only or IPv6-only, and host ports are not allowed.

A mapping with no host address, so it applies to IPv4 and IPv6 when
the default binding is 0.0.0.0, may include a host port if either
uses NAT. The port number is ignored for the directly-routed family.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-11 22:33:58 +01:00
Rob Murray
2a291c1855 Improve PortBinding.String()
Display a PortBinding in a format that's more like the one
used in the CLI, but includes the container IP if known.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-11 22:33:58 +01:00
Rob Murray
a1f8bbeeef Remove unused bridge.driver.portAllocator
It was added so that tests could replace it before it was picked
up and used by a new network's PortMapper, so that tests were isolated
from each other. Now the PortMapper is not used by the bridge driver,
neither is driver's portAllocator.

Instead of replacing the driver.portAllocator in tests, reset the
singleton instance using its ReleaseAll().

Un-export portallocator.NewInstance, now the tests aren't using it.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-11 22:33:58 +01:00
Rob Murray
043db3be68 Bind the same port for multiple addresses
Without this change, if a port mapping did not specify a host address
and the network was IPv6-enabled, the same port would be allocated for
mappings from '0.0.0.0' and '::'. But, if the port mapping was specified
with explicit addresses even, for example:
  -p 0.0.0.0:8080-8083:80 -p '[::]:8083-8080:80'

This change looks for port mappings that only differ in the host IP
address, and makes sure it allocates the same port for all of them. If
it can't, it fails with an error.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-11 22:33:58 +01:00
Rob Murray
20c99e4156 Option to disable NAT for IPv4/IPv6 for a bridge network.
Add bridge driver options...
  com.docker.network.bridge.gateway_mode_ipv4=<nat|routed>
  com.docker.network.bridge.gateway_mode_ipv6=<nat|routed>

If set to "routed", no NAT or masquerade rules are set up for port
mappings.

When NAT is disabled, the mapping is shown in 'inspect' output with
no host port number. For example, for "-p 80" with NAT disabled for
IPv6 but not IPv4:

    "80/tcp": [
        {
            "HostIp": "0.0.0.0",
            "HostPort": "32768"
        },
        {
            "HostIp": "::",
            "HostPort": ""
        }

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-11 22:33:58 +01:00
Tonis Tiigi
18ff5ef537 vendor: update buildkit to v0.14.0
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-11 12:08:34 -07:00
Rob Murray
e05848c002 Set up bridge-specific iptables rules in the bridge driver
Use the bridge driver's iptables types to set up portmapping related
iptables rules - instead of using iptables.Forward, which is bridge
specific code in the iptables package.

Remove iptables.Forward() and its unit test, the bridge driver's
version is covered by TestAddPortMappings.

Remove hairpinMode from iptables.ChainInfo hairpinMode relates to bridge
driver specific behaviour, that is now implemented in the bridge driver.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-11 16:50:16 +00:00
Rob Murray
4f09af6267 Allocate same port for IPv4/IPv6 for 'any interface' mappings.
The bridge driver now does its own port-mapping, rather than using the
portmapper module (which ran as two completely separate instances, for
IPv4 and IPv6).

When asked for a mapping from any host address (0.0.0.0/0) with a range
of host ports, the same port will be allocated for IPv4 and IPv6, or the
mapping will fail with an error if that's not possible.

The bridge driver now manages its own port mappings. So, remove
linux-specific PortMapper code and make what's left Windows-only.

Also, replace the portmapper.userlandProxy interface with StartProxy().

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-11 16:50:15 +00:00
Rob Murray
03577884d9 Retry port mapping for a range if ports are in-use
For a port mapping like '-p 8080-8083:80', when some non-docker process
is using a port in the range, try other ports in the range. And, don't
do that on live-restore.

Because the port mapping may fail on live-restore, leaving no ports
mapped for the endpoint - update the view of mapped ports shown in
'inspect' output. (The wrong mappings will still be shown in 'docker ps',
the container will be left running and connected to the network, it just
won't work. There's plenty of scope for better error handling here.)

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-11 16:50:15 +00:00
Rob Murray
931eea20ff Add portallocator.RequestPortsInRange()
Similar to portallocator.RequestPortInRange(), but it attempts to
allocate the same port for multiple IP addresses.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-11 16:50:15 +00:00
Sebastiaan van Stijn
87794b3030 Merge pull request #47946 from thaJeztah/remove_platforms_platform_alias
remove uses of platforms.Platform alias
2024-06-11 13:38:13 +02:00
Sebastiaan van Stijn
e0b762ed1b daemon/containerd: fix duplicate import
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-11 11:49:57 +02:00
Sebastiaan van Stijn
7f2ed139fe remove uses of platforms.Platform alias
It's an alias for the OCI-spec type, which was only there for
convenience, but will be deprecated.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-11 11:48:01 +02:00
Sebastiaan van Stijn
9d9488468f Merge pull request #47943 from vvoland/c8d-multiplatform-push-2
c8d/push: Fix small whoopsies
2024-06-10 22:14:18 +02:00
Akihiro Suda
89431adcd1 Merge pull request #47500 from AkihiroSuda/fix-47499
seccomp: allow specifying a custom profile with `--privileged`
2024-06-11 05:07:53 +09:00
Akihiro Suda
896de6d426 seccomp: allow specifying a custom profile with --privileged
`--privileged --security-opt seccomp=<CUSTOM.json>` was ignoring
`<CUSTOM.json>`.

Fix issue 47499

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2024-06-11 03:37:54 +09:00
Sebastiaan van Stijn
22c212d208 Merge pull request #47941 from thaJeztah/api_image_inspect_deprecate_fields
api: deprecate erroneous Config fields in `GET /images/{name}/json` response
2024-06-10 19:19:04 +02:00
Paweł Gronowski
2ccce36d10 c8d/progress: Allow updating "Unavailable" ids
They might still change to "Mounted from" or "Already exists" when
containerd updates the status in tracker.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 19:14:23 +02:00
Paweł Gronowski
e2326c27b5 c8d/push: Fix wrong Originalindex descriptor in aux error
The target variable was already overwritten with the new value. Use the
original value instead.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 19:14:21 +02:00
Sebastiaan van Stijn
0566e38cbf Merge pull request #47605 from jonasgeiler/43626-rootless-native-overlay-diff
rootless: overlay2: support native overlay diff when using rootless-mode in kernel 5.11 and above
2024-06-10 18:57:19 +02:00
Sebastiaan van Stijn
1513068d8c Merge pull request #47679 from vvoland/c8d-multiplatform-push
c8d/push: Support `--platform` switch
2024-06-10 18:38:47 +02:00
Sebastiaan van Stijn
af0cdc36c7 api: deprecate erroneous Config fields in GET /images/{name}/json response
The `Config` field returned by this endpoint (used for "image inspect") returns
additional fields that are not part of the image's configuration and not part of
the [Docker Image Spec] and the [OCI Image Spec].

These additional fields are included in the response, due to an
implementation detail, where the [api/types.ImageInspec] type used
for the response is using the [container.Config] type.

The [container.Config] type is a superset of the image config, and while the
image's Config is used as a _template_ for containers created from the image,
the additional fields are set at runtime (from options passed when creating
the container) and not taken from the image Config.

These fields are never set (and always return the default value for the type),
but are not omitted in the response when left empty. As these fields were not
intended to be part of the image configuration response, they are deprecated,
and will be removed from the API.

The following fields are currently included in the API response, but
are not part of the underlying image's Config, and deprecated:

- `Hostname`
- `Domainname`
- `AttachStdin`
- `AttachStdout`
- `AttachStderr`
- `Tty`
- `OpenStdin`
- `StdinOnce`
- `Image`
- `NetworkDisabled` (already omitted unless set)
- `MacAddress` (already omitted unless set)
- `StopTimeout` (already omitted unless set)

[Docker image spec]: https://github.com/moby/docker-image-spec/blob/v1.3.1/specs-go/v1/image.go#L19-L32
[OCI Image Spec]: https://github.com/opencontainers/image-spec/blob/v1.1.0/specs-go/v1/config.go#L24-L62
[api/types.ImageInspec]: https://github.com/moby/moby/blob/v26.1.4/api/types/types.go#L87-L104
[container.Config]: https://github.com/moby/moby/blob/v26.1.4/api/types/container/config.go#L47-L82

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 16:56:17 +02:00
Sebastiaan van Stijn
a736d0701c Merge pull request #47936 from thaJeztah/api_types_container_types
api/types: move more types to sub-packages
2024-06-10 16:51:49 +02:00
Sebastiaan van Stijn
4d40d770cd Merge pull request #47942 from thaJeztah/api_swagger_update_image_config
docs: api: use separate definition for Image.Config (api v1.39 - v1.45)
2024-06-10 16:45:52 +02:00
Sebastiaan van Stijn
58641c7b5c docs: api: use separate definition for Image.Config (api v1.39 - v1.45)
The Image.Config field currently reuses the ContainerConfig definition,
matching the Go implementation, which also uses that type.

However, the ContainerConfig type contains various fields that are not
part of the image config, and would never be set. The Image.Config is
used as template / default values for containers started from the image,
but will only use the fields that are part of the [Docker image spec].

This patch updates the swagger files used in the documentation to use a
separate `ImageConfig` definition for the Image.Config field. The new
definition is a copy of the existing `ContainerConfig` type, but with
updated descriptions for fields, and with an example response that omits
the fields that should not be used.

The following fields are currently included in the `Config` field of the API
response, but are not part of the underlying image's config:

- `Hostname`
- `Domainname`
- `AttachStdin`
- `AttachStdout`
- `AttachStderr`
- `Tty`
- `OpenStdin`
- `StdinOnce`
- `Image`
- `NetworkDisabled` (already omitted unless set)
- `MacAddress` (already omitted unless set)
- `StopTimeout` (already omitted unless set)

[Docker image spec]: https://github.com/moby/docker-image-spec/blob/v1.3.1/specs-go/v1/image.go#L19-L32

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 15:38:18 +02:00
Sebastiaan van Stijn
5e0e34fafd api: swagger: use separate definition for Image.Config
The Image.Config field currently reuses the ContainerConfig definition,
matching the Go implementation, which also uses that type.

However, the ContainerConfig type contains various fields that are not
part of the image config, and would never be set. The Image.Config is
used as template / default values for containers started from the image,
but will only use the fields that are part of the [Docker image spec].

This patch updates the swagger files used in the documentation to use a
separate `ImageConfig` definition for the Image.Config field. The new
definition is a copy of the existing `ContainerConfig` type, but with
updated descriptions for fields, and with an example response that omits
the fields that should not be used.

The following fields are currently included in the `Config` field of the API
response, but are not part of the underlying image's config:

- `Hostname`
- `Domainname`
- `AttachStdin`
- `AttachStdout`
- `AttachStderr`
- `Tty`
- `OpenStdin`
- `StdinOnce`
- `Image`
- `NetworkDisabled` (already omitted unless set)
- `MacAddress` (already omitted unless set)
- `StopTimeout` (already omitted unless set)

[Docker image spec]: https://github.com/moby/docker-image-spec/blob/v1.3.1/specs-go/v1/image.go#L19-L32

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 15:37:27 +02:00
Sebastiaan van Stijn
a24e3f2ac6 Merge pull request #47799 from j2walker/47648-dameon-health-start-interval-default-value-fix
Changed default value of the startInterval to 5s
2024-06-10 14:36:02 +02:00
Paweł Gronowski
8d96d759bb c8d/image_manifest: IsPseudoImage return true for unknown/unknown platform
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 13:35:17 +02:00
Paweł Gronowski
b4d2283c89 api/push: Ignore Platform on older APIs
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 13:35:15 +02:00
Paweł Gronowski
68a63d0611 c8d/push: Extract missing content note to an Aux progress
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 13:35:14 +02:00
Paweł Gronowski
0a31437208 c8d/push: Support platform selection
Add a OCI platform fields as parameters to the `POST /images/{id}/push`
that allow to specify a specific-platform manifest to be pushed instead
of the whole image index.

When no platform was requested and pushing whole index failed, fallback
to pushing a platform-specific manifest with a best candidate (if it's
possible to choose one).

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 13:35:13 +02:00
Paweł Gronowski
999f1c63db testutils/specialimage: Add MultiPlatform
Add utility that allows to construct an image with the specified
platforms.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 13:35:12 +02:00
Paweł Gronowski
c16d676266 c8d/blobsDirContentStore: Return ErrNotExists
Translate os.ErrNotExist into cerrdefs.ErrNotExists

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 13:35:11 +02:00
Paweł Gronowski
85249a8401 c8d/image_manifest: Add helper functions
This adds the common helper functions used by the recent
multiplatform-related PRs.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-10 13:35:10 +02:00
Jack Walker
c514952774 Changed default value of the startInterval to 5s
Co-authored-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Jack Walker <90711509+j2walker@users.noreply.github.com>
2024-06-10 13:23:26 +02:00
Paweł Gronowski
ac064904b8 Merge pull request #47927 from crazy-max/ci-buildkit-debug
ci: enable debug for buildkit container builder
2024-06-10 11:57:41 +02:00
Sebastiaan van Stijn
04110fa774 Merge pull request #47919 from laurazard/fix-deprecated-otel
otel: remove deprecated usages of `otelgrpc`
2024-06-10 11:53:26 +02:00
Sebastiaan van Stijn
6e514e8993 Merge pull request #47932 from thaJeztah/reexec_clean
pkg/reexec: cleanup and remove some dependencies
2024-06-10 11:31:01 +02:00
Sebastiaan van Stijn
aa22d137e9 Merge pull request #47937 from thaJeztah/client_fix_test_typos
client: fix typos in test-names and godoc
2024-06-10 10:37:28 +02:00
Sebastiaan van Stijn
b6ee4b66ad Merge pull request #47931 from thaJeztah/graphdriver_remove_Mounted
daemon/graphdriver: remove redundant Mounted function
2024-06-10 10:22:11 +02:00
Sebastiaan van Stijn
6c2934f373 api/types: move ImageLoadResponse to api/types/image
This moves the type, but we should consider removing this type, and just
returning an io.ReadCloser

This type was added in 9fd2c0feb0c131d01d727d50baa7183b976c7bdc;

> Make docker load to output json when the response content type is json
> Swarm hijacks the response from docker load and returns JSON rather
> than plain text like the Engine does. This makes the API library to return
> information to figure that out.

However the "load" endpoint unconditionally returns JSON;
7b9d2ef6e5/api/server/router/image/image_routes.go (L248-L255)

Commit 96d7db665b made the response-type depend
on whether "quiet" was set, but this logic got changed in a follow-up
2f27632cde, which made the JSON response-type
unconditionally, but the output produced depend on whether"quiet" was set.

We should deprecated the "quiet" option, as it's really a client
responsibility.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:25 +02:00
Sebastiaan van Stijn
eb675cce71 api/types: move ImageImportSource to api/types/image
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:25 +02:00
Sebastiaan van Stijn
f6cc76ceb9 api/types: move ImageSearchOptions to api/types/registry
Note that RequestPrivilegeFunc could not be referenced, as it would
introduce a circular import, so copying the definition instead.

Also combining the other search-related types in the package to be in
the same file.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:24 +02:00
Sebastiaan van Stijn
b5f15bc0aa api/types: move EventsOptions to api/types/events
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:24 +02:00
Sebastiaan van Stijn
ecb24afaaf api/types: move ImagesPruneReport to api/types/image
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:24 +02:00
Sebastiaan van Stijn
162ef4f8d1 api/types: move VolumesPruneReport to api/types/volume
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:24 +02:00
Sebastiaan van Stijn
17c3269a37 api/types: move ContainerStats to api/types/container
This is the response type; other types related to stats are left
for now, but should be moved (as well as utilities ported from
the CLI repository).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:21:22 +02:00
Sebastiaan van Stijn
fd1d8f323b api/types: move CopyToContainerOptions to api/types/container
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:20:47 +02:00
Sebastiaan van Stijn
47d7c9e31d api/types: move ContainerPathStat to api/types/container
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:20:45 +02:00
Sebastiaan van Stijn
db2f1acd5d api/types: move ContainersPruneReport to api/types/container
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:19:47 +02:00
Sebastiaan van Stijn
5b27e71521 api/types: move ContainerExecInspect to api/types/container
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:19:46 +02:00
Sebastiaan van Stijn
d91638e295 api/types: move ExecStartCheck to api/types/container
This moves the type to api/types/container and creates an alias for
exec attach; ContainerExecAttach currently uses the same type as
ContainerExecStart, but does not all the same options (and some
options cannot be used).

We need to split the actual types, but lets start with aliasing.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:19:46 +02:00
Sebastiaan van Stijn
452e134001 api/types: move ExecStartOptions to api/types/backend
It's a type used by the backend, so moving it there.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:19:46 +02:00
Sebastiaan van Stijn
cd76e3e7f8 api/types: move ExecConfig to api/types/container
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-10 10:19:46 +02:00
Paweł Gronowski
3d2ee590a0 Merge pull request #47935 from thaJeztah/remove_TestContainerAPICopyNotExistsAnyMore
integration-cli: remove DockerAPISuite.TestContainerAPICopyNotExistsAnyMore
2024-06-10 10:18:00 +02:00
Sebastiaan van Stijn
8c34c63d81 Merge pull request #47939 from thaJeztah/api_remove_container_containerconfig
docs: api: image inspect: remove Container and ContainerConfig
2024-06-10 10:06:08 +02:00
Sebastiaan van Stijn
3434a8ef6e Merge pull request #47938 from thaJeztah/vendor_pty
vendor: github.com/creack/pty v1.1.21
2024-06-10 10:05:43 +02:00
Sebastiaan van Stijn
e314cbdab8 Merge pull request #47862 from thaJeztah/exec_router_nits
api/server/router/container: minor nits in exec router
2024-06-10 10:05:18 +02:00
Sebastiaan van Stijn
ac27a5379b docs: api: image inspect: remove Container and ContainerConfig
The Container and ContainerConfig fields have been deprecated, and removed
since API v1.45 in commit 03cddc62f4.

This patch fixes the swagger and documentation to no longer mention them
as they are no longer returned by API v1.45 and higher.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-09 23:17:37 +02:00
Sebastiaan van Stijn
52580b2673 vendor: github.com/creack/pty v1.1.21
full diff: https://github.com/creack/pty/compare/v1.1.18...v1.1.21

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-09 22:39:33 +02:00
Sebastiaan van Stijn
fa95f8a070 client: fix typos in test-names and godoc
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-09 22:35:04 +02:00
Sebastiaan van Stijn
311c949871 Merge pull request #47731 from racequite/master
chore: fix function names in comment
2024-06-09 22:33:09 +02:00
Akihiro Suda
7b9d2ef6e5 Merge pull request #47934 from thaJeztah/vendor_reference_0.6
vendor: github.com/distribution/reference v0.6.0
2024-06-09 05:15:13 +09:00
Akihiro Suda
59875a9218 Merge pull request #47933 from thaJeztah/bump_bbolt_1.3.10
vendor: go.etcd.io/bbolt v1.3.10
2024-06-09 05:14:57 +09:00
Sebastiaan van Stijn
08939f21ad integration-cli: remove DockerAPISuite.TestContainerAPICopyNotExistsAnyMore
This test was added in 428328908dc529b1678fb3d8b033fb0591a294e3;

> Deprecate /containers/(id or name)/copy endpoint
> This endpoint has been deprecated since 1.8. Return an error starting
> from this API version (1.24) in order to make sure it's not used for the
> next API version and so that we can remove it sometimes later.

We deprecated and removed those older API versions, and the test was
effectively only verifying that a non-existing endpoint returns a 404,
so let's remove it.

This also removes api/types.CopyConfig, which was only used in this
test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 21:00:25 +02:00
Sebastiaan van Stijn
75843620a6 api/server/router/container: minor nits in exec router
- remove intermediate variable
- format a "todo" comment as an actual todo ':)
- explicitly suppress some unhandled errors to keep linters happy

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 20:54:38 +02:00
Sebastiaan van Stijn
18e1afd1a1 vendor: github.com/distribution/reference v0.6.0
full diff: https://github.com/distribution/reference/compare/v0.5.0...v0.6.0

- remove deprecated SplitHostname
- refactor splitDockerDomain to include more documentation
- fix typo in readme
- Exclude domain from name length check

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 17:51:50 +02:00
Sebastiaan van Stijn
7529e95f6f Merge pull request #47918 from robmry/allow_startup_with_no_ip6tables
Allow startup with no kernel support for ip6_tables
2024-06-08 16:10:54 +02:00
Sebastiaan van Stijn
7501b90a22 vendor: go.etcd.io/bbolt v1.3.10
- Remove deprecated UnsafeSlice and use unsafe.Slice
- Stabilize the behaviour of Prev when the cursor already points to
  the first element
    - Fix Cursor.Prev() out of range issues in v1.3.9
    - Relates to boltdb/bolt/issues/357 (Cursor inconsistent when mixing
      cursor.Delete() with Put() in same transaction)
- Bump go version to 1.21.9

full diff: https://github.com/etcd-io/bbolt/compare/v1.3.9...v1.3.10

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 15:16:45 +02:00
Sebastiaan van Stijn
cf796aa56a pkg/reexec: touch-up GoDoc, and remove "import" comments
Touch-up some GoDoc in the package, and remove "import" comments.

This package is used in BuildKit, and could be a potential candidate
for moving to a separate module. The "import" comments are ignored when
used in go module mode so have little benefit. Let's remove them.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 14:18:13 +02:00
Sebastiaan van Stijn
d20a074f33 pkg/reexec: remove gotest.tools from tests
This package is used in BuildKit, and could be a potential candidate
for moving to a separate module. While it's not too problematic to have
this dependency, the tests only used basic assertions from gotest.tools,
which could be easily re-implemented without the dependency.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 14:18:12 +02:00
Sebastiaan van Stijn
defd5a08f4 pkg/reexec: unify non-Linux implementation of Command
The Windows, Darwin, and FreeBSD implementations were identical, other
than their GoDoc to be different. Unify them so that we don't have to
maintain separate GoDoc for each.

It's worth noting that FreeBSD also supports Pdeathsig, so could be
using the same implementation as Linux. However, we don't test/maintain
the FreeBSD implementation, and it would require updating to GoDoc to
be more specific about the use of `/proc/self/exe`, so keeping the
status quo for now.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 14:18:12 +02:00
Sebastiaan van Stijn
004451c812 pkg/reexec: unify implementation of Self() and remove stub
This combines the implementations of the Self function, to allow having
a single GoDoc to document the behavior. The naiveSelf function is kept,
because it's used in unit-tests.

There is a minor change in behavior, as this patch removes the stub for
unsupported platforms (non-linux, windows, freebsd or darwin), which will
now use `os.Args[0]`. The stub was added in 21537b818d
to fix compilation of https://github.com/ethereum/go-ethereum on OpenBSD,
which had docker/docker as dependency. It looks like that repository no
longer has this dependency, and as this was only to make the code
compilable, is unlikely to be a problem.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 14:18:11 +02:00
Sebastiaan van Stijn
79bff9461c pkg/reexec: don't mix syscall and golang.org/x/sys package
commit 069fdc8a08 changed most uses of
the syscall package to switch utsname from unsigned to signed (see
069fdc8a08). Those don't seem to be
impacting the code used here, so either stdlib or golang.org/x/sys/unix
should work for this case.

I chose stdlib's syscall package for this case, in case we'd decide to
move this package to a separate module (and want to limit its dependencies).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 14:18:11 +02:00
Sebastiaan van Stijn
a445f7fa8a daemon/graphdriver: fix GoDoc for ProtoDriver.GetMetadata
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 12:20:55 +02:00
Sebastiaan van Stijn
a76b768fea daemon/graphdriver: remove redundant Mounted function
This function largely identical to GetFSMagic, except for suppressing
ENOENT errors. The only consumer of this function was fsChecker.IsMounted,
which would ignore errors either way, and only use the "success" case to
check if the detected filesystem-type was the expected one.

This patch;

- rewrites fsChecker.IsMounted to use GetFSMagic instead
- removes the now unused Mounted function

As we consider daemon/graphdriver to be "internal", and as there are no
public consumers of this, we can remove this function without deprecating
first.

The freebsd implementation also seemed to be broken, as it mixed syscall
with golang.org/x/sys/unix, which used incompatible types. I left the file
in place for now, but we can consider removing it altogether as there's no
active development on making freebsd functional.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-08 12:13:56 +02:00
Rob Murray
837b3f9576 Allow startup with no kernel support for ip6_tables
Before "ip6tables" was enabled by default, dockerd would start normally
when:
- the kernel had no IPv6 support, or
- docker is running as docker-in-docker, and the host doesn't have kernel
  module 'ip6_tables' loaded.

Now, the bridge driver will try to set up its ip6tables chains and it'll
fail. By not treating that as an error, the daemon will start and IPv4
will work normally.

A subsequent attempt to create an IPv6 network will fail with an error
about ip6tables. At that point, the user's options are:
- set "ip6tables":false in daemon config
- in the DinD case, "modprobe ip6_tables" on the host, or start dockerd
  on the host with ip6tables enabled (causing the kernel module load).

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-07 17:40:38 +01:00
Sebastiaan van Stijn
4fb17cb3af Merge pull request #47928 from akerouanton/rob-maintainer
Add Rob Murray (@robmry) as maintainer
2024-06-07 17:54:39 +02:00
Albin Kerouanton
4df4f83f23 Merge pull request #47926 from akerouanton/revert-47837
Revert "libnet/i/defaultipam: Disambiguate PoolID string format"
2024-06-07 16:32:39 +02:00
Albin Kerouanton
fd3fa4b28a Add Rob Murray (@robmry) as maintainer
Rob is currently a curator, and has been actively contributing to this
repo for 7 months now.

Beside day-to-day triaging and bug fixing, Rob is an instrumental
contributor to libnetwork, and amongst other things, to the ongoing work
on IPv6 improvements.

I nominated Rob as maintainer, and votes passed, so opening a PR to make
it official.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-07 16:18:46 +02:00
Laura Brehm
854130eee0 deps: remove grpc-ecosystem/go-grpc-middleware
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-06-07 14:35:52 +01:00
Laura Brehm
49ca0d0d03 otel: remove deprecated usages of otelgrpc
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
2024-06-07 14:35:51 +01:00
Albin Kerouanton
1243f9da6d Revert "libnet/i/defaultipam: Disambiguate PoolID string format"
This reverts commit 9369132879.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-07 15:32:13 +02:00
Albin Kerouanton
6af0646236 Revert "libnet/i/defaultipam: Use InternalErrorf instead of InvalidParameterErrof"
This reverts commit 5a2fa59688.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-07 15:31:54 +02:00
CrazyMax
4aa85cd159 ci: enable debug for buildkit container builder
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-06-07 15:30:22 +02:00
Sebastiaan van Stijn
59996a493c Merge pull request #47866 from cncal/return_container_annotations
api/server: ContainerList returns container annotations
2024-06-07 14:14:12 +02:00
Sebastiaan van Stijn
aa2c7de9b9 Merge pull request #47924 from thaJeztah/api_checkduplicates_optional
api/types/network: make CheckDuplicate optional
2024-06-07 13:35:07 +02:00
Sebastiaan van Stijn
fc9dd6acb4 api/types/network: make CheckDuplicate optional
The CheckDuplicate option is no longer part of the current API; it's
only used by the client when connecting to old API versions, which need
to have this field set.

This patch:

- Removes the CheckDuplicate from the API documentation, as the API
  describes the current version of the API (which does not have this
  field).
- Moves the CheckDuplicate field to the CreateRequest type; this is
  the type used for the network create request. The CheckDuplicate
  is not an option that's set by the user, and set internally by
  the client, so removing it from the CreateOptions struct moves
  it entirely internal.
- Change the CheckDuplicate field to be a pointer; this makes the
  "omitempty" become active, and the client will no longer include
  the field in the request JSON unless it's set (API < 1.44).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-07 12:06:39 +02:00
Sebastiaan van Stijn
f6d8ac04ba Merge pull request #47921 from thaJeztah/api_move_network_create
api/types: move NetworkCreate, NetworkCreateRequest, NetworksPruneReport to api/types/network
2024-06-07 12:06:28 +02:00
Sebastiaan van Stijn
e5f9484ab6 api/types: move NetworksPruneReport to api/types/network
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-07 11:14:52 +02:00
Sebastiaan van Stijn
ad6edc139f api/types: move NetworkCreate, NetworkCreateRequest to api/types/network
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-07 11:11:15 +02:00
Sebastiaan van Stijn
b75bca3868 Merge pull request #47922 from tonistiigi/20240606-update-buildkit
vendor: update buildkit to v0.14.0-rc2
2024-06-07 08:47:43 +02:00
Tonis Tiigi
4f61fa21cb vendor: update buildkit to v0.14.0-rc2
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-06 18:59:02 -07:00
cncal
ca0529f984 api/server: ContainerList returns container annotations
Allow clients (e.g. cri-dockerd) to fetch container annotations in
ContainerList api.

Signed-off-by: cncal <flycalvin@qq.com>
2024-06-07 09:50:11 +08:00
Sebastiaan van Stijn
181e70cc07 Merge pull request #47920 from thaJeztah/bump_appengine
vendor: google.golang.org/appengine v1.6.8
2024-06-06 20:47:26 +02:00
Sebastiaan van Stijn
00f18ef7a4 Merge pull request #47867 from akerouanton/api-EnableIPv6-override
api: Make EnableIPv6 optional (impl #1 - pointer-based)
2024-06-06 20:20:29 +02:00
Sebastiaan van Stijn
6f32dc19f1 Merge pull request #47683 from vvoland/buildkit-update
vendor: github.com/moby/buildkit v0.14.0-rc2-dev
2024-06-06 16:59:14 +02:00
Sebastiaan van Stijn
b3c8216873 vendor: google.golang.org/appengine v1.6.8
removes use of the deprecated "golang.org/x/net/context" package

full diff: https://github.com/golang/appengine/compare/v1.6.7...v1.6.8

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-06 15:28:58 +02:00
Paweł Gronowski
0b5f7b9ff8 builder-next: Adjust NewGatewayFrontend invocation
b5c50afa882e2b34aba880fd5028615e2ef94e07 changed the signature of
NewGatewayFrontend to include a slice of allowed repositories.

Docker does not allow to specify this option, so don't place any
restrictions by passing an empty slice.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-06 11:20:18 +02:00
Jonathan A. Sternberg
fa03db1b82 builder: Update detect usage for new detect API from buildkit
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-06 11:20:17 +02:00
Paweł Gronowski
995604236e builder: Adjust usage of shlex.ProcessWord
1b1c5bc08ad81add007eb647e66ed0929693f3a0 extended the function signature
with one additional return value.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-06 11:20:16 +02:00
Paweł Gronowski
438371e1fe builder: Pass nil linter to instructions.Parse
eea0b41bf4fb1d69e109ff5ff8045c63f0c0d510 added a new argument to
`instructions.Parse` to support issuing linter warnings.

Classic builder uses it to parse the Dockerfile instructions and its
usage needs adjustment.

The classic builder is deprecated and we won't be adding any new
features to it, so we just pass a nil linter callback.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-06 11:20:15 +02:00
Paweł Gronowski
3bcbb561ad vendor: update github.com/moby/buildkit to v0.14.0-rc2-dev
- full diff: https://github.com/moby/buildkit/compare/v0.13.1...v0.14.0-rc2

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-06 11:20:13 +02:00
Albin Kerouanton
f3f20c3a86 Merge pull request #47602 from robmry/internal_resolver_for_default_bridge
Add resolver for default bridge, remove default nameservers
2024-06-06 10:39:24 +02:00
Rob Murray
d365702dbd No default nameservers for internal resolver
Don't fall-back to Google's DNS servers in a network that has an
internal resolver.

Now the default bridge uses the internal resolver, the only reason a
network started by the daemon should end up without any upstream
servers is if the host's resolv.conf doesn't list any.  In this case,
the '--dns' option can be used to explicitly configure nameservers
for a container if necessary.

(Note that buildkit's containers do not have an internal resolver, so
they will still set up Google's nameservers if the host has no
resolvers that can be used in the container's namespace.)

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-05 20:27:24 +01:00
Rob Murray
18f4f775ed Internal resolver for default bridge network
Until now, containers on the default bridge network have been configured
to talk directly to external DNS servers - their resolv.conf files have
either been populated with nameservers from the host's resolv.conf, or
with servers from '--dns' (or with Google's nameservers as a fallback).

This change makes the internal bridge more like other networks by using
the internal resolver.  But, the internal resolver is not populated with
container names or aliases - it's only for external DNS lookups.

Containers on the default network, on a host that has a loopback
resolver (like systemd's on 127.0.0.53) will now use that resolver
via the internal resolver. So, the logic used to find systemd's current
set of resolvers is no longer needed by the daemon.

Legacy links work just as they did before, using '/etc/hosts' and magic.

(Buildkit does not use libnetwork, so it can't use the internal resolver.
But it does use libnetwork/resolvconf's logic to configure resolv.conf.
So, code to set up resolv.conf for a legacy networking without an internal
resolver can't be removed yet.)

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-05 20:27:24 +01:00
Albin Kerouanton
c6aaabc9fc Merge pull request #47887 from thaJeztah/move_more_network_api_types_2
api/types: migrate NetworkResource to api/types/network
2024-06-05 15:48:24 +02:00
Sebastiaan van Stijn
c5c4abbf59 Merge pull request #47909 from thaJeztah/vendor_containerd_1.7.18
vendor: github.com/containerd/containerd v1.7.18
2024-06-05 12:33:04 +02:00
Paweł Gronowski
1a4efd2c74 Merge pull request #47910 from thaJeztah/bump_containerd_binary_1.7.18
update containerd binary to v1.7.18
2024-06-05 11:56:40 +02:00
Sebastiaan van Stijn
5318c38eae update containerd binary to v1.7.18
Update the containerd binary that's used in CI and for the static packages.

- release notes: https://github.com/containerd/containerd/releases/tag/v1.7.18
- full diff: https://github.com/containerd/containerd/compare/v1.7.17...v1.7.18

Welcome to the v1.7.18 release of containerd!

The eighteenth patch release for containerd 1.7 contains various updates along
with an updated version of Go. Go 1.22.4 and 1.21.11 include a fix for a symlink
time of check to time of use race condition during directory removal.

Highlights

- Update Go version to 1.21.11
- Remove uses of platforms.Platform alias
- Migrate log imports to github.com/containerd/log
- Migrate errdefs package to github.com/containerd/errdefs
- Fix usage of "unknown" platform

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-05 10:18:42 +02:00
Paweł Gronowski
189dc1b47e Merge pull request #47902 from thaJeztah/bump_go1.21.11
update to go1.21.11
2024-06-05 10:14:19 +02:00
Sebastiaan van Stijn
86f7762d48 vendor: github.com/containerd/containerd v1.7.18
Update to containerd 1.7.18, which now migrated to the errdefs module. The
existing errdefs package is now an alias for the module, and should no longer
be used directly.

This patch:

- updates the containerd dependency: https://github.com/containerd/containerd/compare/v1.7.17...v1.7.18
- replaces uses of the old package in favor of the new module
- adds a linter check to prevent accidental re-introduction of the old package
- adds a linter check to prevent using the "log" package, which was also
  migrated to a separate module.

There are still some uses of the old package in (indirect) dependencies,
which should go away over time.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-05 09:21:00 +02:00
Sebastiaan van Stijn
91e2c29865 update to go1.21.11
go1.21.11 (released 2024-06-04) includes security fixes to the archive/zip
and net/netip packages, as well as bug fixes to the compiler, the go command,
the runtime, and the os package. See the Go 1.21.11 milestone on our issue
tracker for details;

- https://github.com/golang/go/issues?q=milestone%3AGo1.21.11+label%3ACherryPickApproved
- full diff: https://github.com/golang/go/compare/go1.21.10...go1.21.11

From the security announcement;

We have just released Go versions 1.22.4 and 1.21.11, minor point releases.
These minor releases include 2 security fixes following the security policy:

- archive/zip: mishandling of corrupt central directory record

  The archive/zip package's handling of certain types of invalid zip files
  differed from the behavior of most zip implementations. This misalignment
  could be exploited to create an zip file with contents that vary depending
  on the implementation reading the file. The archive/zip package now rejects
  files containing these errors.

  Thanks to Yufan You for reporting this issue.

  This is CVE-2024-24789 and Go issue https://go.dev/issue/66869.

- net/netip: unexpected behavior from Is methods for IPv4-mapped IPv6 addresses

  The various Is methods (IsPrivate, IsLoopback, etc) did not work as expected
  for IPv4-mapped IPv6 addresses, returning false for addresses which would
  return true in their traditional IPv4 forms.

  Thanks to Enze Wang of Alioth and Jianjun Chen of Zhongguancun Lab
  for reporting this issue.

  This is CVE-2024-24790 and Go issue https://go.dev/issue/67680.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-04 23:23:27 +02:00
Albin Kerouanton
216e426ec2 Merge pull request #47901 from thaJeztah/cluster_remove_getRequestContext
daemon/cluster: remove Cluster.getRequestContext()
2024-06-04 22:18:50 +02:00
Albin Kerouanton
163c6ca9ad api: Make EnableIPv6 optional
Currently, starting dockerd with
`--default-network-opt=bridge=com.docker.network.enable_ipv6=true` has
no effect as `NetworkCreateRequest.EnableIPv6` is a basic bool.

This change makes it a `*bool` to make it optional. If clients don't
specify it, the default-network-opt will be applied.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-06-04 21:36:18 +02:00
Sebastiaan van Stijn
83c532c9b7 daemon/cluster: remove Cluster.getRequestContext()
This method was added in 534a90a993 as
part of adding the Swarm cluster backend, and later updated in commit
85b1fdf15c to use a swarmRequestTimeout
const for the timeout.

Nothing in this utility depends on the Cluster struct, and the abstraction
makes it appear as more than it is, which is just a wrapper for
context.WithTimeout().

Let's remove the abstraction to make it less magical.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-04 18:09:58 +02:00
Sebastiaan van Stijn
69b2a05d27 api/types: migrate NetworkResource to api/types/network
This moves the type to the api/types/network package, but also introduces
a "Summary" alias; the intent here is to allow diverging the types used
for "list" and "inspect" operations, as list operations may only be
producing a subset of the fields available.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-04 17:44:46 +02:00
Sebastiaan van Stijn
a865453b1a Merge pull request #47900 from thaJeztah/api_types_rm_deprecated_aliases
api/types: remove aliases for deprecated Image types
2024-06-04 17:17:32 +02:00
Sebastiaan van Stijn
3306034c64 api/types: remove aliases for deprecated Image types
These aliases were added in ac2a028dcc,
which was part of the v26.0 and v26.1 releases. We can remove the
aliases, assuming users that depended on this have migrated to the
new location of these types.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-04 16:01:22 +02:00
Sebastiaan van Stijn
989426d303 Merge pull request #47897 from thaJeztah/rm_deprecated_inspectoptions
integration/network: remove used of deprecated NetworkInspectOptions
2024-06-04 14:13:51 +02:00
Sebastiaan van Stijn
70bac42113 integration/network: remove used of deprecated NetworkInspectOptions
The types.NetworkInspectOptions type was moved to the networks package
in 5bea0c38bc and deprecated, but use of it
was re-introduced in cd3804655a, which was
merged out-of-order.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-04 11:53:00 +02:00
Albin Kerouanton
cd3804655a Merge pull request #47853 from akerouanton/libnet-ipam-default-ula
libnet/i/defaultipam: use ULA prefix by default
2024-06-04 00:05:41 +02:00
Lei Jitang
58aac7773d Merge pull request #47888 from thaJeztah/opts_remove_alias
opts: remove alias for ipamutils
2024-06-03 19:17:07 +08:00
Sebastiaan van Stijn
8c400f4f37 Merge pull request #47886 from thaJeztah/cleanup_httpstatus_fromerror
api/server/httpstatus: FromError: remove redundant checks and cleanup
2024-06-03 12:35:55 +02:00
Sebastiaan van Stijn
1ec92ea60b opts: remove alias for ipamutils
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-03 12:27:40 +02:00
Sebastiaan van Stijn
1f359403fe Merge pull request #47881 from thaJeztah/client_cleanups
client: minor cleanup, linting- and bug-fixes
2024-06-03 11:43:27 +02:00
Sebastiaan van Stijn
e6f41e22a7 client: Client.doRequest: fix closing filehandle and reversed errors
commit 1a5dafb31e improved the error messages
produced by adding a check if the client is using as an elevated user. For
this, it attempts to open `\\.\PHYSICALDRIVE0`.

However, it looks like closing the file landed in the wrong branch of the
condition, so the file-handle would not be closed when the os.Open succeeded.

Looking further into this check, it appears the conditions were reversed;
if the check _fails_, it means the user is not running with elevated
permissions, but the check would use elevatedErr == nil.

Fix both by changing the condition to `elevatedErr != nil`.

While at it, also changing the string to use a string-literal, to reduce
the amount of escaping needed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-03 10:52:15 +02:00
Sebastiaan van Stijn
9110ef1eec client: ensureReaderClosed: make linters happier
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-03 10:52:15 +02:00
Sebastiaan van Stijn
57f597b866 client: Client.NetworkInspectWithRaw: minor cleanup
Make this code slightly more idiomatic, and make it clear in what cases
we don't return an actual response, but an empty / default struct.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-03 10:52:15 +02:00
Sebastiaan van Stijn
42f4db26c7 api/server/httpstatus: FromError: remove redundant checks and cleanup
- remove redundant `if statusCode == 0 {` check, which would always be true
- use early returns in the switch
- move all conditions into the switch, and scope the `statusCode` variable
  to conditions where it's used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-03 09:47:50 +02:00
Sebastiaan van Stijn
4318ab0b33 Merge pull request #47882 from thaJeztah/move_more_network_api_types
api/types: migrate NetworkListOptions to api/types/network
2024-06-01 15:50:40 +02:00
Sebastiaan van Stijn
f78dac35e5 api/types: migrate NetworkListOptions to api/types/network
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-31 17:41:31 +02:00
Sebastiaan van Stijn
e622cea556 Merge pull request #47873 from thaJeztah/move_more_network_api_types
api/types: move more networking-types to api/types/network
2024-05-30 21:56:42 +02:00
Albin Kerouanton
d18b88fd32 daemon: add ULA prefix by default
So far, Moby only had IPv4 prefixes in its 'default-address-pools'. To
get dynamic IPv6 subnet allocations, users had to redefine this
parameter to include IPv6 base network(s). This is needlessly complex
and against Moby's 'batteries-included' principle.

This change generates a ULA base network by deriving a ULA Global ID
from the Engine's Host ID and put that base network into
'default-address-pools'. This Host ID is stable over time (except if
users remove their '/var/lib/docker/engine-id') and thus the GID is
stable too.

This ULA base network won't be put into 'default-address-pools' if users
have manually configured it.

This is loosely based on https://datatracker.ietf.org/doc/html/rfc4193#section-3.2.2.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-29 22:38:27 +02:00
Sebastiaan van Stijn
68bf0e7625 api/types: migrate EndpointResource to api/types/network
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-29 19:22:37 +02:00
Sebastiaan van Stijn
5bea0c38bc api/types: migrate NetworkInspectOptions to api/types/network
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-29 19:22:37 +02:00
Sebastiaan van Stijn
245d12175f api/types: migrate NetworkConnect, NetworkDisconnect to api/types/network
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-29 19:22:37 +02:00
Sebastiaan van Stijn
89624e09e6 api/types: migrate NetworkCreateResponse to network.CreateResponse
Migrate the type to the network package, and generate it from swagger.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-29 19:22:34 +02:00
Albin Kerouanton
2ebf19129f Merge pull request #47686 from robmry/47639_per-interface-sysctls
Per-interface sysctls
2024-05-29 10:54:05 +02:00
Albin Kerouanton
32418e9753 daemon: set the default local addr pool if none configured
Until this commit, the default local address pool was initialized by the
defaultipam driver if none was provided by libnet / the daemon.

Now, defaultipam errors out if none is passed and instead the daemon is
made responsible for initializing it with the default values if the user
don'te set the related config parameter.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-29 10:47:59 +02:00
Rob Murray
0071832226 Add per-endpoint sysctls to DriverOpts
Until now it's been possible to set per-interface sysctls using, for
example, '--sysctl net.ipv6.conf.eth0.accept_ra=2'. But, the index in
the interface name is allocated serially, and the numbering in a container
with more than one interface may change when a container is restarted.
The change to make it possible to connect a container to more than one
network when it's created increased the ambiguity.

This change adds label "com.docker.network.endpoint.sysctls" to the
DriverOpts in EndpointSettings. This option is explicitly associated
with the interface.

Settings in "--sysctl" for "eth0" are migrated to DriverOpts.

Because using "--sysctl" with any interface apart from "eth0" would have
unpredictable results, it is now an error to use any other interface name
in the top level "--sysctl" option. The error message includes a hint at
how to use the new per-interface setting.

The per-endpoint sysctl name has the interface name replaced by
"IFNAME". For example:
    net.ipv6.conf.eth0.accept_ra=2
becomes:
    net.ipv6.conf.IFNAME.accept_ra=2

The value of DriverOpts["com.docker.network.endpoint.sysctls"] is a
comma separated list.

Settings from '--sysctl' are applied by the runtime lib during task
creation. So, task creation fails if the endpoint does not exist.
Applying per-endpoint settings during interface configuration means the
endpoint can be created later, which paves the way for removal of the
SetKey OCI prestart hook.

Unlike other DriverOpts, the sysctl label itself is not driver-specific,
but each driver has a chance to check settings/values and raise an error
if a setting would cause it a problem - no such checks have been added
in this initial version. As a future extension, if required, it would be
possible for the driver to echo back valid/extended/modified settings to
libnetwork for it to apply to the interface. (At that point, the syntax
for the options could become driver specific to allow, for example, a
driver to create more than one interface).

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-29 08:59:48 +01:00
Sebastiaan van Stijn
56a43a7618 Merge pull request #47865 from thaJeztah/api_docs_network_config_only
api: networking: document Scope, ConfigOnly, ConfigFrom, Peers
2024-05-28 23:52:05 +02:00
Sebastiaan van Stijn
ce0ccc09ff Merge pull request #45313 from akerouanton/deprecate-cors-headers
Deprecate dockerd api-cors-header parameter
2024-05-28 23:42:53 +02:00
Sebastiaan van Stijn
4e07c49336 Merge pull request #47092 from thaJeztah/bump_docker_py
update docker-py to 7.1.0
2024-05-28 20:42:00 +02:00
Sebastiaan van Stijn
e5532c52aa Merge pull request #47861 from thaJeztah/integration_nits
integration/system, integration/container: minor cleanups
2024-05-28 19:56:41 +02:00
Sebastiaan van Stijn
c96a2dbb54 Merge pull request #47860 from thaJeztah/test_nits
integration/internal/swarm, testutil/fakestorage: fix minor (linting) issues
2024-05-28 19:55:06 +02:00
Bjorn Neergaard
9a7d8c8660 Merge pull request #47863 from thaJeztah/platforms_err_handling
don't depend on containerd platform.Parse to return a typed error
2024-05-28 08:01:52 -06:00
Sebastiaan van Stijn
347bb4122a update docker-py to 7.1.0
full diff: https://github.com/docker/docker-py/compare/7.0.0...7.1.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-28 11:38:54 +02:00
Sebastiaan van Stijn
69f1e2a923 docs/api: add Scope, ConfigOnly, ConfigFrom, Peers (v1.41 - v1.45)
- api: swagger: Network: inline examples, and add ConfigOnly, ConfigFrom

  These fields were added in 9ee7b4dda9, but
  not documented in the API docs / swagger.

  Also move the example values per-field to reduce the risk of the example
  given from diverging with the actual struct that's used for the request.

- api: swagger: POST /networks/create: document Scope, ConfigOnly, ConfigFrom

  Adds missing documentation for Scope, ConfigOnly, and ConfigFrom. The ConfigOnly
  and ConfigFrom fields were added in 9ee7b4dda9,
  but not documented in the API docs / swagger.

- api: swagger: Network: add Peers

  Add documentation for the Peers field.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-27 21:30:28 +02:00
Sebastiaan van Stijn
53542fefd5 api: swagger: Network: add Peers
Add documentation for the Peers field.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-27 21:28:48 +02:00
Sebastiaan van Stijn
44125530bf api: swagger: POST /networks/create: document Scope, ConfigOnly, ConfigFrom
Adds missing documentation for Scope, ConfigOnly, and ConfigFrom. The ConfigOnly
and ConfigFrom fields were added in 9ee7b4dda9,
but not documented in the API docs / swagger.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-27 21:28:48 +02:00
Sebastiaan van Stijn
8b7a54f622 api: swagger: Network: inline examples, and add ConfigOnly, ConfigFrom
These fields were added in 9ee7b4dda9, but
not documented in the API docs / swagger.

Also move the example values per-field to reduce the risk of the example
given from diverging with the actual struct that's used for the request.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-27 21:28:41 +02:00
Sebastiaan van Stijn
6cab6d0302 docs/api: POST /networks/create: inline examples per-field (v1.41 - v1.45)
Move the example values per-field to reduce the risk of the example given
from diverging with the actual struct that's used for the request.

This patch updates older API versions (went back to v1.41).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-27 17:49:06 +02:00
Sebastiaan van Stijn
51885166b9 api: swagger: POST /networks/create: inline examples per-field
Move the example values per-field to reduce the risk of the example given
from diverging with the actual struct that's used for the request.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-27 17:36:05 +02:00
Sebastiaan van Stijn
d64e220afb api/types: NetworkCreate: add GoDoc
GoDoc is mostly copied from NetworkResource, which is the equivalent for
retrieving the information.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-27 16:25:18 +02:00
Sebastiaan van Stijn
cd1ed46d73 don't depend on containerd platform.Parse to return a typed error
We currently depend on the containerd platform-parsing to return typed
errdefs errors; the new containerd platforms module does not return such
errors, and documents that errors returned should not be used as sentinel
errors; c1438e911a/errors.go (L21-L30)

Let's type these errors ourselves, so that we don't depend on the error-types
returned by containerd, and consider that eny platform string that results in
an error is an invalid parameter.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-27 10:18:29 +02:00
Sebastiaan van Stijn
56086c9952 integration/container: remove redundant type-conversion, and minor cleanup
- Remove redundant conversion to strslice.StrSlice
- Use assert.Check where possible to not fail early
- Remove instances of types.ExecStartCheck that used default values
- Minor code-formatting cleanup

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-25 14:58:52 +02:00
Sebastiaan van Stijn
070e90a94c integration/system: remove redundant type-conversion, and minor cleanup
- Remove redundant conversion to strslice.StrSlice
- Use assert.Assert instead of assert.Check to fail early if value is nil
- Minor code-formatting cleanup

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-25 14:56:44 +02:00
Sebastiaan van Stijn
667094924d testutil/fakestorage: fix minor (linting) issues
- fix typo in comment
- rename variable that collided with an import
- add log for an unhandled error
- slightly improve error-logs

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-25 14:00:09 +02:00
Sebastiaan van Stijn
4a074c809e integration/internal/swarm: remove unused ContainerPoll
This was added in ee6959addc to account
for arm (32) requiring a longer timeout at the time, but it was never
used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-25 13:57:39 +02:00
Sebastiaan van Stijn
fe78d6d9da integration/internal/swarm: rename vars that collided with imports
- rename the client var to not collide with the imported client package
- remove an intermediate startCheck variable

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-25 13:55:59 +02:00
Brian Goff
4619b14403 refactor: rename attach config var
This var for the incoming attach request.
Just within this one function we also have `cfg`, and `ctr` already, so
`c` just makes things more confusing.
Not to mention `c` is usually referencing a container object in other
parts of the code.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2024-05-24 21:32:18 +00:00
Brian Goff
2d134c5abd Fix goroutine/fd leak when client disconnects
In cases where the client disconnects and there is nothing to read from
a stdio stream after that disconnect, the copy goroutines and file
descriptors are leaked because `io.Copy` is just blocked waiting for
data from the container's I/O stream.

This fix only applies to Linux.
Windows will need a separate fix.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2024-05-24 21:32:15 +00:00
Sebastiaan van Stijn
ceefb7d0b9 Merge pull request #47855 from thaJeztah/bump_buildx
Dockerfile: update buildx to v0.14.1, compose v2.27.1
2024-05-24 19:00:37 +02:00
Albin Kerouanton
62ddd3dea8 Merge pull request #47747 from robmry/non-experimental-ip6tables
Enable 'ip6tables' by default, don't require 'experimental'.
2024-05-24 18:38:16 +02:00
Sebastiaan van Stijn
8361baf8d9 Dockerfile: update compose to v2.27.1
release notes: https://github.com/docker/compose/releases/tag/v2.27.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-24 14:53:58 +02:00
Sebastiaan van Stijn
387be6ec91 Dockerfile: update buildx to v0.14.1
- 0.14.1 release notes: https://github.com/docker/buildx/releases/tag/v0.14.1
- 0.14.0 release notes: https://github.com/docker/buildx/releases/tag/v0.14.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-24 14:44:01 +02:00
Sebastiaan van Stijn
5cd2e6a1b7 Merge pull request #47854 from dperny/fix-manager-promote-race
Fix issue where node promotion could fail
2024-05-23 21:14:58 +02:00
Brian Goff
b0f7117b31 Merge pull request #47850 from weebney/patch-1
Replace dead RFC8878 hyperlink in documentation
2024-05-23 15:57:40 +00:00
Albin Kerouanton
d16a425f0f Merge pull request #47768 from akerouanton/libnet-ipam-linear-allocator
libnet/ipams/default: introduce a linear allocator
2024-05-23 11:07:12 +02:00
Albin Kerouanton
500eff0ae9 libnet/i/defaultipam: improve address pools validation
Nothing was validating whether address pools' `base` prefix
were larger than the target subnet `size` they're associated to. As
such invalid address pools would yield no subnet, the error could go
unnoticed.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-23 08:26:07 +02:00
Albin Kerouanton
0c022307e9 libnet/i/defaultipam: Unmap IPv4-mapped IPv6 addrs
This ensures such address pools are part of the IPv4 address space.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-23 08:26:00 +02:00
Albin Kerouanton
9d288b5b43 libnet/i/defaultipam: introduce a linear allocator
The previous allocator was subnetting address pools eagerly
when the daemon started, and would then just iterate over that
list whenever RequestPool was called. This was leading to high
memory usage whenever IPv6 pools were configured with a target
subnet size too different from the pools prefix size.

For instance: pool = fd00::/8, target size = /64 -- 2 ^ (64-8)
subnets would be generated upfront. This would take approx.
9 * 10^18 bits -- way too much for any human computer in 2024.

Another noteworthy issue, the previous implementation was allocating
a subnet, and then in another layer was checking whether the
allocation was conflicting with some 'reserved networks'. If so,
the allocation would be retried, etc... To make it worse, 'reserved
networks' would be recomputed on every iteration. This is totally
ineffective as there could be 'reserved networks' that fully overlap
a given address pool (or many!).

To fix this issue, a new field `Exclude` is added to `RequestPool`.
It's up to each driver to take it into account. Since we don't know
whether this retry loop is useful for some remote IPAM driver, it's
reimplemented bug-for-bug directly in the remote driver.

The new allocator uses a linear-search algorithm. It takes advantage
of all lists (predefined pools, allocated subnets and reserved
networks) being sorted and logically combines 'allocated' and
'reserved' through a 'double cursor' to iterate on both lists at the
same time while preserving the total order. At the same time, it
iterates over 'predefined' pools and looks for the first empty space
that would be a good fit.

Currently, the size of the allocated subnet is still dictated by
each 'predefined' pools. We should consider hardcoding that size
instead, and let users specify what subnet size they want. This
wasn't possible before as the subnets were generated upfront. This
new allocator should be able to deal with this easily.

The method used for static allocation has been updated to make sure
the ascending order of 'allocated' is preserved. It's bug-for-bug
compatible with the previous implementation.

One consequence of this new algorithm is that we don't keep track
of where the last allocation happened, we just allocate the first
free subnet we find.

Before:

- Allocate: 10.0.1.0/24, 10.0.2.0/24 ; Deallocate: 10.0.1.0/24 ;
Allocate 10.0.3.0/24.

Now, the 3rd allocation would yield 10.0.1.0/24 once again.

As it doesn't change the semantics of the allocator, there's no
reason to worry about that.

Finally, about 'reserved networks'. The heuristics we use are
now properly documented. It was discovered that we don't check
routes for IPv6 allocations -- this can't be changed because
there's no such thing as on-link routes for IPv6.

(Kudos to Rob Murray for coming up with the linear-search idea.)

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-23 08:24:51 +02:00
Albin Kerouanton
5f183b9b3a Merge pull request #47837 from akerouanton/libnet-ipam-disambiguate-PoolID
libnet/i/defaultipam: Disambiguate PoolID string format
2024-05-22 22:52:15 +02:00
weebney
a9ebb0c267 Replace dead RFC8878 go doc hyperlink
Fixes #45952

Signed-off-by: weebney <weebney@gmail.com>
2024-05-22 14:27:15 -04:00
Sebastiaan van Stijn
274b2932a1 Merge pull request #47838 from dmcgowan/update-containerd-v1.7.17
Update containerd to v1.7.17
2024-05-22 17:36:21 +02:00
Drew Erny
16e5c41591 Fix issue where node promotion could fail
If a node is promoted right after another node is demoted, there exists
the possibility of a race, by which the newly promoted manager attempts
to connect to the newly demoted manager for its initial Raft membership.
This connection fails, and the whole swarm Node object exits.

At this point, the daemon nodeRunner sees the exit and restarts the
Node.

However, if the address of the no-longer-manager is recorded in the
nodeRunner's config.joinAddr, the Node again attempts to connect to the
no-longer-manager, and crashes again. This repeats. The solution is to
remove the node entirely and rejoin the Swarm as a new node.

This change erases config.joinAddr from the restart of the nodeRunner,
if the node has previously become Ready. The node becoming Ready
indicates that at some point, it did successfully join the cluster, in
some fashion. If it has successfully joined the cluster, then Swarm has
its own persistent record of known manager addresses. If no joinAddr is
provided, then Swarm will choose from its persisted list of managers to
join, and will join a functioning manager.

Signed-off-by: Drew Erny <derny@mirantis.com>
2024-05-22 08:48:03 -05:00
Albin Kerouanton
5a2fa59688 libnet/i/defaultipam: Use InternalErrorf instead of InvalidParameterErrof
InvalidParameterErrorf was used whenever an invalid value was found
during PoolID unmarshaling. This error is converted to a 400 HTTP code
by the HTTP server.

However, users never provide PoolIDs directly -- these are constructed
from user-supplied values which are already validated when the PoolID is
marshaled. Hence, if such erroneous value is found, it's an internal
error and should be converted to a 500.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-22 10:02:20 +02:00
Albin Kerouanton
9369132879 libnet/i/defaultipam: Disambiguate PoolID string format
Prior to this change PoolID microformat was using slashes to separate
fields. Those fields include subnet prefixes in CIDR notation, which
also include a slash. This makes future evolution harder than it should
be.

This change introduces a 'v2' microformat based on JSON. This has two
advantages:

1. Fields are clearly named to ensure each value is associated to the
right field.
2. Field values and separators are clearly distinguished to remove any
ambiguity.

The 'v1' encoding will be kept until the next major MCR LTS is released.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-22 10:02:19 +02:00
Sebastiaan van Stijn
8470add2fe Merge pull request #47840 from vvoland/update-containerd
Dockerfile: update containerd binary to v1.7.17 (static binaries and CI only)
2024-05-21 23:16:00 +02:00
Albin Kerouanton
081f6ba39a Merge pull request #47826 from robmry/windns_proxy_default
Default to "windows-dns-proxy":true
2024-05-21 17:19:09 +02:00
Sebastiaan van Stijn
c3a40873f9 Merge pull request #47820 from akerouanton/libnet-store-is-never-nil-followup
libnet: Controller: more c.store clean-ups
2024-05-21 15:27:40 +02:00
Albin Kerouanton
6d21574535 libnet: Controller: drop getStore()
This method does nothing more than `return c.store`. It has no value and
adds an unecessary level of indirection. Let's ditch it.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-21 12:54:57 +02:00
Albin Kerouanton
49888559cc libnet: Controller: drop closeStores
Previous commit made it clear that c.store can't be nil. Hence,
`c.store.Close()` can be called without checking if c.store is nil.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-21 12:43:48 +02:00
Albin Kerouanton
2336363e28 libnet: init datastore in ctrler constructor
This was done in a separate method, called by the ctrler constructor.
This method was returning a nil datastore when c.cfg was nil -- but that
can't happen in practice!

This was giving the impression that the controller could be run without
a datastore properly configured. It's not the case, so make it explicit
by instantiating the datastore before `Controller`.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-21 12:43:48 +02:00
Paweł Gronowski
3847da374b integration/TestDiskUsage: Make 4096 also a 'empty' value
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-05-21 12:35:01 +02:00
Albin Kerouanton
145a73a36c Merge pull request #47818 from akerouanton/libnet-d-bridge-dont-parse-MacAddress-netlabel
libnet/d/bridge: don't parse the MacAddress netlabel
2024-05-21 10:12:16 +02:00
Rob Murray
1e29f9b12f Move EndpointSettings.DriverOpts from op-state to config
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-17 11:30:14 +01:00
Rob Murray
a35716f5b9 Factor out selection of endpoint for config migration
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-17 11:30:14 +01:00
Paweł Gronowski
4f0cb7d964 Dockerfile: update containerd binary to v1.7.17 (static binaries and CI only)
Update the containerd binary that's used in CI and static binaries

- full diff: https://github.com/containerd/containerd/compare/v1.7.15...v1.7.17
- release notes: https://github.com/containerd/containerd/releases/tag/v1.7.17

```markdown changelog
Update containerd (static binaries only) to [v1.7.17](https://github.com/containerd/containerd/releases/tag/v1.7.17)
```

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-05-17 11:07:11 +02:00
Derek McGowan
e459487feb Update containerd to v1.7.17
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-05-16 15:24:38 -07:00
Sebastiaan van Stijn
06e3a49d66 Merge pull request #47796 from cpuguy83/fix_superfluous_write_header
Explicity write http headers on streaming endpoints
2024-05-16 23:12:57 +02:00
Brian Goff
707ab48cbb Explicity write http headers on streaming endpoints
This works around issues with the otel http handler wrapper causing
multiple calls to `WriteHeader` when a `Flush` is called before `Write`.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2024-05-16 18:00:02 +00:00
Brian Goff
50d3028464 Fix fd leak/goroutine when attaching stdin only
When only stdin is attached the goroutine can only ever exit if:

1. The container pipe is closed while trying to write to it
2. The client closes the stdin read pipe

This is because `io.Copy` does a read on the read side then a write to
the write side.
If reading from the client's stdin pipe blocks, the goroutine will never
get notified that the container pipe is closed.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2024-05-16 16:49:07 +00:00
Sebastiaan van Stijn
ae976b998b Merge pull request #47629 from vvoland/tarexport-tracing-ctx-cancel
tarexport: Plumb ctx, add OTEL spans, handle cancellation
2024-05-14 14:14:51 +02:00
Paweł Gronowski
ad0f263eb5 tarexport: Plumb ctx, add OTEL spans, handle cancellation
Pass `context.Context` through `tarexport.Load` and `tarexport.Save`.
Create OTEL spans for the most time consuming operations.

Also, handle context cancellations to actually end saving/loading when
the operation is cancelled - before this PR the daemon would still be
performing the operation even though the user already cancelled it.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-05-14 13:08:33 +02:00
Albin Kerouanton
5505c851f1 Merge pull request #47821 from robmry/internal_network_with_dns
Forward DNS requests into --internal networks
2024-05-14 12:22:49 +02:00
Rob Murray
33f9a5329a Default to "windows-dns-proxy":true
In 26.1, we added daemon feature flag "windows-dns-proxy" which could
be set to "true" to make "nslookup" work in Windows containers, by
forwarding requests from the internal resolver to the container's
external DNS servers.

This changes the default to forwarding-enabled - it can be disabled by
via daemon.json using ...
  "features": { "windows-dns-proxy": false }

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-13 11:11:20 +01:00
Rob Murray
77a47dba3b Forward DNS requests into --internal networks
A recent change to prevent containers only connected to --internal
networks from communicating with external DNS servers inadvertently
prevented the daemon's internal DNS server from forwarding requests
within an internal network to a containerised DNS server.

Relax the check, so that only requests that need to be forwarded
from the host's network namespace are dropped.

External DNS servers remain unreachable from the internal network.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-10 19:36:55 +01:00
Albin Kerouanton
cd08d377c5 Merge pull request #47819 from akerouanton/libnet-d-remote-replace-errorWithRollback
libnet/d/remote: replace errorWithRollback
2024-05-10 13:26:41 +02:00
Albin Kerouanton
6fbae5ff26 libnet/d/bridge: don't parse the MacAddress netlabel
Libnet's method `(*Network).createEndpoint()` is already parsing this
netlabel to set the field `ep.iface.mac`. Later on, this same method
invoke the driver's method `CreateEndpoint` with an `InterfaceInfo` arg
and an `options` arg (an opaque map of driver otps).

The `InterfaceInfo` interface contains a `MacAddress()` method that
returns `ep.iface.mac`. And the opaque map may contain the key
`netlabel.MacAddress`.

Prior to this change, the bridge driver was calling `MacAddress()`. If
no value was returned, it'd fall back to the option set in the `options`
map, or generate a MAC address based on the IP address.

However, the expected type of the `options` value is a `net.HardwareAddr`.
This is what's set by the daemon when handing over the endpoint config
to libnet controller. If the value is a string, as is the case if the
MAC address is provided through `EndpointsSettings.DriverOpts`, it
produces an error.

As such, the opaque option and the `MacAddress()` are necessarily the
same -- either nothing or a `net.HardwareAddr`. No need to keep both.

Moreover, the struct `endpointConfiguration` was only used to store that
netlabel value. Drop it too.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-10 12:45:12 +02:00
Rob Murray
41ddc47bbf Don't explicitly enable ip6tables in tests
Tests no longer need to use "--experimental --ip6tables", now ip6tables
is the default behaviour.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-10 10:17:30 +01:00
Rob Murray
07ccaf028d Enable 'ip6tables' by default, don't require 'experimental'.
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-10 09:21:21 +01:00
Rob Murray
5705cbf6e3 Make it an error to set up filtering on an unnamed bridge
In setupIPv6BridgeNetFiltering(), the bridge should always be named.
Don't fall back to checking the "default" setting for a new bridge.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-10 09:21:21 +01:00
Rob Murray
d6b6a5122f Enable filtering on IPv6 bridges with no IPv6 address
Check forwarding, then set bridge-nf-call-ip6tables, on a bridge
if IPv6 is enabled - even if no IPv6 address has been assigned.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-10 09:21:21 +01:00
Rob Murray
4df97f2e1e Gate setting of bridge-nf-call-ip6tables on "--ip6tables=true".
The code to enable "bridge-nf-call-iptables" or "bridge-nf-call-ip6tables"
was gated on "--iptables=true", it didn't check "--ip6tables=true".

So, split the top level call into IPv4/IPv6 so that the iptables-enable
settings can be checked independently, and simplfied the implementation.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-10 09:21:21 +01:00
Rob Murray
8751562d3f Set up IPv6 n/w isolation rules when --ip6tables=true
bridgeNetwork.isolateNetwork() checks "--iptables=true" and
"--ip6tables=true" before doing anything with IPv4 and IPv6
respectively.  But, it was only called if "--iptables=true".

Now, it's called if "--ip6tables=true", even if "--iptables=false".

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-10 09:21:21 +01:00
Rob Murray
23fd15985b Allow "--ip6tables=true" when "--iptables=false"
The bridge driver's setupIPChains() had an initial sanity check that
"--iptables=true".

But, it's called with "version=IPv6" when "--iptables=false" and
"--ip6tables=true" - the sanity test needed to allow for that.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-10 09:21:21 +01:00
Rob Murray
9a8ffe38fc Disable ip6tables in tests that disable iptables
Tests that start a daemon disable iptables, to avoid conflicts with
other tests running in parallel and also creating iptables chains.

Do the same for ip6tables, in prep for them being enabled by-default.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-10 09:21:21 +01:00
Albin Kerouanton
75821a7d9a Merge pull request #47787 from robmry/47778_preserve_kernel_ll_addrs
Preserve kernel-assigned IPv6 link-local addresses on a bridge network's bridge
2024-05-10 10:18:11 +02:00
Albin Kerouanton
a9ded90030 Merge pull request #47788 from robmry/bad_integration-cli_ipv6_tests
Fix/remove broken integration-cli IPv6 tests
2024-05-10 10:17:48 +02:00
Albin Kerouanton
5952920380 libnet/d/remote: replace errorWithRollback
Use defer funcs instead.

For no apparant reasons, a few error cases in the Join method were not
triggering a rollback. This is now fixed.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-10 10:15:11 +02:00
Sebastiaan van Stijn
64da0e0b13 Merge pull request #47810 from akerouanton/libnet-store-is-never-nil
libnet: don't check if ctrler store is nil
2024-05-09 13:10:12 +02:00
Albin Kerouanton
7216541b17 libnet: don't check if ctrler store is nil
Since commit befff0e1, `(*Controller).getStore()` never returns nil
except if `c.store` isn't initialized yet. This can't happen unless
`New()` returned an error and it wasn't proper caught.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-05-08 12:37:30 +02:00
Albin Kerouanton
7ea9acc97f cmd/dockerd: deprecate api-cors-header
CORS headers were originally added by 6d5bdff.

These headers could be set without any Authz plugin enabled
beforehand, making this feature quite dangerous.

This commit marks the daemon flag `api-cors-header` as deprecated
and requires the env var `DOCKERD_DEPRECATED_CORS_HEADER` to be
set. When enabled, the daemon will write a deprecation warning to
the logs and the endpoint `GET /info` will return the same
deprecation warning.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-08 12:12:09 +02:00
Paweł Gronowski
4554d871d7 Merge pull request #47805 from vvoland/update-go
update to go1.21.10
2024-05-08 10:58:54 +02:00
Paweł Gronowski
6c97e0e0b5 update to go1.21.10
- https://github.com/golang/go/issues?q=milestone%3AGo1.21.10+label%3ACherryPickApproved
- full diff: https://github.com/golang/go/compare/go1.21.9...go1.21.10

These minor releases include 2 security fixes following the security policy:

- cmd/go: arbitrary code execution during build on darwin
On Darwin, building a Go module which contains CGO can trigger arbitrary code execution when using the Apple version of ld, due to usage of the -lto_library flag in a "#cgo LDFLAGS" directive.
Thanks to Juho Forsén of Mattermost for reporting this issue.
This is CVE-2024-24787 and Go issue https://go.dev/issue/67119.

- net: malformed DNS message can cause infinite loop
A malformed DNS message in response to a query can cause the Lookup functions to get stuck in an infinite loop.
Thanks to long-name-let-people-remember-you on GitHub for reporting this issue, and to Mateusz Poliwczak for bringing the issue to our attention.
This is CVE-2024-24788 and Go issue https://go.dev/issue/66754.

View the release notes for more information:
https://go.dev/doc/devel/release#go1.22.3

**- Description for the changelog**

```markdown changelog
Update Go runtime to 1.21.10
```

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-05-08 09:31:46 +02:00
Albin Kerouanton
4d525c9009 Merge pull request #47744 from robmry/47716_no_dns_req_to_self
Do not forward DNS requests to self.
2024-05-07 18:24:41 +02:00
Albin Kerouanton
da3f60bfe4 Merge pull request #47745 from robmry/firewalld_forwarding_policy
Add firewalld policy "docker-forwarding".
2024-05-07 15:52:26 +02:00
Paweł Gronowski
440836a8cf Merge pull request #47003 from LarsSven/fix-container-start-time
Move StartedAt time to before starting the container
2024-05-07 14:58:27 +02:00
Paweł Gronowski
8e14f278c4 Merge pull request #47651 from vvoland/api-bump
API: bump version to 1.46
2024-05-07 10:40:07 +02:00
Sebastiaan van Stijn
9314eaff2f Merge pull request #47797 from cpuguy83/bundles_aint_phony
Makefile: bundles is not PHONY
2024-05-06 08:02:24 +02:00
Brian Goff
ac71ac1c92 Merge pull request #47664 from crazybolillo/47516-crazybolillo 2024-05-03 14:23:15 -07:00
Brian Goff
72eb615490 Makefile: bundles is not PHONY
This was changed recently so that the bundles target is always run, but
`mkdir bundles` fails when bundles exists...

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2024-05-03 21:01:12 +00:00
Sebastiaan van Stijn
a73e63cfa6 Merge pull request #47656 from imalasong/pr/1
Makefile: refactoring .PHONY
2024-05-03 00:19:31 +02:00
Sebastiaan van Stijn
5d03db29d8 Merge pull request #47749 from woky/apparmor-runc
apparmor: Allow confined runc to kill containers
2024-05-02 20:50:06 +02:00
Rob Murray
fda708f55d Delete broken/unused test requirement helper "IPv6"
It'd only return true on a host with no IPv6 in its kernel.

So, removed, having fixed the two tests that used it.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-01 19:28:16 +01:00
Rob Murray
4aff2fbc98 Remove integration-cli TestDaemonSuite/TestDaemonIPv6Enabled
The test hadn't been running, because it used testRequires(c, IPv6)
and predicate "IPv6" returns the opposite of the expected result.

TestDaemonIPv6Enabled tried to run with IPv6 on the default bridge,
but didn't set up a "fixed-cidr-v6" - so the daemon wouldn't start.

It then tried to check the bridge had address "fe80::1", which it
expected to work because it had just used setupV6() to add that
address.

Then it  checked that "LinkLocalIPv6Address" was set in container
inspect output, but it wouldn't be (the field is deprecated).

There are working IPv6 tests in the suite (TestDaemonIPv6FixedCIDR,
TestDaemonIPv6FixedCIDRAndMac, TestDaemonIPv6HostMode) - and there's
more coverage in the network integration tests.

So, deleted the test as it didn't seem worth salvaging.

Also deleted now-unused helper functions setupV6(), teardownV6().

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-01 19:26:06 +01:00
Rob Murray
346a7c07a0 Fix TestDockerSwarmSuite/TestSwarmInitIPv6
The test hadn't been running, because it used testRequires(c, IPv6)
and predicate "IPv6" returns the opposite of the expected result.

If the test had run, it'd have failed because:
- it used "--listen-add", but the option is "--listen-addr"
  - so, the daemon wouldn't have started
- it tried to use "--join ::1"
  - address "::1" was interpreted as host:port so the Dial() failed,
    it needed to be "[::1]".
  - it didn't supply a  join token

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-01 19:09:54 +01:00
Rob Murray
b11e95f5bc Don't delete IPv6 multicast addresses from a bridge
Multicast addresses aren't added by the daemon so, if they're present,
it's because they were explicitly added - possibly to a user-managed
bridge. So, don't remove.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-01 17:46:08 +01:00
Rob Murray
a5f82ba4bf Disallow IPv6 multicast as bridge n/w subnet
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-01 17:20:56 +01:00
Rob Murray
aa3a86c038 Refactor IPv6 subnet validation
- Remove package variable bridge.bridgeIPv6
- Use netip in more places
- Improve error messages from fixed-cidr-v6 checks

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-01 17:20:56 +01:00
Rob Murray
f46473b29c Do not remove kernel-ll addresses from bridges
Make the behaviour enabled by env var DOCKER_BRIDGE_PRESERVE_KERNEL_LL
the default...
- don't remove kernel assigned link-local addresses
  - or any address in fe80::/64
- don't assign fe80::1 to a bridge

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-01 17:20:56 +01:00
Paweł Gronowski
9d07820b22 Merge pull request #47771 from robmry/dont_delete_kernel_ll_addrs
Option to avoid deleting the kernel_ll address from bridges.
2024-04-30 11:27:30 +02:00
Sebastiaan van Stijn
22892d2210 Merge pull request #47572 from avoidaway/master
chore: remove repetitive words
2024-04-30 08:53:53 +02:00
Sebastiaan van Stijn
8cbd20246c Merge pull request #47769 from robmry/47751_readonly_procsysnet
Allow for a read-only "/proc/sys/net".
2024-04-29 21:43:45 +02:00
Rob Murray
01ea18f1e3 Allow for a read-only "/proc/sys/net".
If dockerd runs on a host with a read-only /proc/sys/net filesystem,
it isn't able to enable or disable IPv6 on network interfaces when
attaching a container to a network (including initial networks during
container creation).

In release 26.0.2, a read-only /proc/sys/net meant container creation
failed in all cases.

So, don't attempt to enable/disable IPv6 on an interface if it's already
set appropriately.

If it's not possible to enable IPv6 when it's needed, just log (because
that's what libnetwork has always done if IPv6 is disabled in the
kernel).

If it's not possible to disable IPv6 when it needs to be disabled,
refuse to create the container and raise an error that suggests setting
environment variable "DOCKER_ALLOW_IPV6_ON_IPV4_INTERFACE=1", to tell
the daemon it's ok to ignore the problem.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-04-29 16:17:06 +01:00
Rob Murray
57ada4b848 Option to avoid deleting the kernel_ll address from bridges.
If env var DOCKER_BRIDGE_PRESERVE_KERNEL_LL=1, don't assign fe80::1/64
to a bridge, and don't delete any link local address with prefix fe80::/64.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-04-28 17:01:59 +01:00
Albin Kerouanton
48d769bf2f Merge pull request #47727 from akerouanton/libnet-ipam-cleanup
libnet/ipam: Various clean-ups
2024-04-26 22:42:53 +02:00
Albin Kerouanton
c5376e534c libnet/ipams/null: move driver name to its pkg
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:29 +02:00
Albin Kerouanton
f2387f3632 libnet/ipams/defaultipam: move driver name to its pkg
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:29 +02:00
Albin Kerouanton
0db56de78e libnet/ipamutils: no more global state
Prior to this change, cnmallocator would call
`ConfigGlobalScopeDefaultNetworks` right before initializing its
IPAM drivers. This function was mutating some global state used
during drivers init.

This change just remove the global state, and adds an arg to
ipams.Register and defaultipam.Register to pass the global pools
by arguments instead.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:29 +02:00
Albin Kerouanton
3c9718144f libnet/ipams: register all drivers
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:29 +02:00
Albin Kerouanton
eda47500fc libnet/ipams: Unconditionally call windowsipam.Register
This function is made a no-op on non-windows platform.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:29 +02:00
Albin Kerouanton
ae9e4319b0 libnet/ipams/windowsipam: that driver knows its name
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:29 +02:00
Albin Kerouanton
8cec9f0dca libnet/ipams/defaultipam: add a Register fn
All drivers except the default have a Register function. Before this
change, default's registration was handled by another package. Move
this logic into the driver pkg.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:29 +02:00
Albin Kerouanton
218394cada libnet/ipams/builtin: move to libnet/ipams
Packages in libnet/ipams are drivers, except builtin -- it's used
to register drivers. Move files one level up and delete this pkg.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:29 +02:00
Albin Kerouanton
29f2ca04e0 libnet: move ipam pkg to ipam/defaultipam
All drivers except the default ipam driver are stored in ipams/.
Since `default` isn't a valid Go pkg name, this package is
renamed to `defaultipam`, following `windowsipam` example.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:29 +02:00
Albin Kerouanton
e8644c3e0e libnet/ipam: default-address-pools as Register arg
Prior to this change, daemon's `default-address-pools` param would
be passed to `SetDefaultIPAddressPool()` to set a global var named
`defaultAddressPool`. This var would then be retrieved during the
`default` IPAM driver registration. Both steps were executed in
close succession during libnet's controller initialization.

This change removes the global var and just pass the user-defined
`default-address-pools` to the `default` driver's `Register` fn.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:29 +02:00
Albin Kerouanton
1d5a12dfb1 integration-cli: createNetwork: add t.Helper()
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:29 +02:00
Albin Kerouanton
115de5ff3d libnet/ipamapi: add in/out structs for RequestPool
The `RequestPool` method has many args and named returns. This
makes the code hard to follow at times. This commit adds one struct,
`PoolRequest`, to replace these args, and one struct, `AllocatedPool`,
to replace these named returns.

Both structs' fields are properly documented to better define their
semantics, and their relationship with address allocation.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 17:28:26 +02:00
Albin Kerouanton
82aae0fe50 libnet/netutils: remove dead util NetworkRange
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 16:10:39 +02:00
Albin Kerouanton
37a81cd04d libnet/ipam: split v4/v6 address spaces
Address spaces are a continuum of addresses that can be used for a
specific purpose (ie. 'local' for unmanaged containers, 'global for
Swarm). v4 and v6 addresses aren't of the same size -- hence
combining them into a single address space doesn't form a continuum.
Better set them apart into two different address spaces.

Also, the upcoming rewrite of `addrSpace` will benefit from that
split.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 16:07:57 +02:00
Albin Kerouanton
199c72cb5d libnet/ipam: remove dead DumpDatabase()
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 16:06:40 +02:00
Albin Kerouanton
df88857e6c libnet/ipam: put addrSpace into a separate file
`addrSpace` methods are currently scattered in two different files.
As upcoming work will rewrite some of these methods, better put them
into a separate file.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 16:06:40 +02:00
Albin Kerouanton
a047d4b1df libnet/ipam: un-embed mutex from addrSpace
Embedding `sync.Mutex` into a struct is considered a bad practice
as it makes the mutex methods part of the embedding struct's API.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-04-26 16:06:40 +02:00
Sebastiaan van Stijn
16b2c223ce Merge pull request #47536 from Benehiko/docker-client-ctx-reduced
feat: ctx to client API
2024-04-26 15:21:00 +02:00
Paweł Gronowski
dda4fec99a Merge pull request #47763 from dmcgowan/update-containerd-1.7.16
vendor: update containerd to v1.7.16
2024-04-26 11:00:28 +02:00
Derek McGowan
eeec716e33 Update containerd to v1.7.16
Includes fix for HTTP fallback

Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-04-25 15:35:15 -07:00
Jonas Geiler
efca9303a4 refactor: updated native diff error message
Signed-off-by: Jonas Geiler <git@jonasgeiler.com>
Co-authored-by: Akihiro Suda <suda.kyoto@gmail.com>
2024-04-25 21:30:10 +02:00
Rob Murray
ff8de5e156 Add firewalld policy "docker-forwarding".
Allow forwarding from any firewalld zone to the 'docker' zone.

This makes it possible to use routable IPv6 addresses on a bridge
network, with masquerading disabled, and have the host forward packets
to it.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-04-24 16:44:43 +01:00
Tomáš Virtus
5ebe2c0d6b apparmor: Allow confined runc to kill containers
/usr/sbin/runc is confined with "runc" profile[1] introduced in AppArmor
v4.0.0. This change breaks stopping of containers, because the profile
assigned to containers doesn't accept signals from the "runc" peer.
AppArmor >= v4.0.0 is currently part of Ubuntu Mantic (23.10) and later.

In the case of Docker, this regression is hidden by the fact that
dockerd itself sends SIGKILL to the running container after runc fails
to stop it. It is still a regression, because graceful shutdowns of
containers via "docker stop" are no longer possible, as SIGTERM from
runc is not delivered to them. This can be seen in logs from dockerd
when run with debug logging enabled and also from tracing signals with
killsnoop utility from bcc[2] (in bpfcc-tools package in Debian/Ubuntu):

  Test commands:

    root@cloudimg:~# docker run -d --name test redis
    ba04c137827df8468358c274bc719bf7fc291b1ed9acf4aaa128ccc52816fe46
    root@cloudimg:~# docker stop test

  Relevant syslog messages (with wrapped long lines):

    Apr 23 20:45:26 cloudimg kernel: audit:
      type=1400 audit(1713905126.444:253): apparmor="DENIED"
      operation="signal" class="signal" profile="docker-default" pid=9289
      comm="runc" requested_mask="receive" denied_mask="receive"
      signal=kill peer="runc"
    Apr 23 20:45:36 cloudimg dockerd[9030]:
      time="2024-04-23T20:45:36.447016467Z"
      level=warning msg="Container failed to exit within 10s of kill - trying direct SIGKILL"
      container=ba04c137827df8468358c274bc719bf7fc291b1ed9acf4aaa128ccc52816fe46
      error="context deadline exceeded"

  Killsnoop output after "docker stop ...":

    root@cloudimg:~# killsnoop-bpfcc
    TIME      PID      COMM             SIG  TPID     RESULT
    20:51:00  9631     runc             3    9581     -13
    20:51:02  9637     runc             9    9581     -13
    20:51:12  9030     dockerd          9    9581     0

This change extends the docker-default profile with rules that allow
receiving signals from processes that run confined with either runc or
crun profile (crun[4] is an alternative OCI runtime that's also confined
in AppArmor >= v4.0.0, see [1]). It is backward compatible because the
peer value is a regular expression (AARE) so the referenced profile
doesn't have to exist for this profile to successfully compile and load.

Note that the runc profile has an attachment to /usr/sbin/runc. This is
the path where the runc package in Debian/Ubuntu puts the binary. When
the docker-ce package is installed from the upstream repository[3], runc
is installed as part of the containerd.io package at /usr/bin/runc.
Therefore it's still running unconfined and has no issues sending
signals to containers.

[1] https://gitlab.com/apparmor/apparmor/-/commit/2594d936
[2] https://github.com/iovisor/bcc/blob/master/tools/killsnoop.py
[3] https://download.docker.com/linux/ubuntu
[4] https://github.com/containers/crun

Signed-off-by: Tomáš Virtus <nechtom@gmail.com>
2024-04-24 13:07:48 +02:00
Rob Murray
87506142d8 Do not forward DNS requests to self.
If a container is configured with the internal DNS resolver's own
address as an external server, try the next ext server rather than
recursing (return SERVFAIL if there are no other servers).

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-04-24 09:15:35 +01:00
Sebastiaan van Stijn
faf84d7f0a Merge pull request #47743 from thaJeztah/bump_go_winio
vendor: github.com/Microsoft/go-winio v0.6.2 (for go1.22 compatibility)
2024-04-23 14:47:40 +02:00
Paweł Gronowski
70475b371b Merge pull request #47739 from thaJeztah/vendor_ebpf
vendor: github.com/cilium/ebpf v0.12.3
2024-04-23 12:58:02 +02:00
Paweł Gronowski
c95b0a97c5 Merge pull request #47742 from vvoland/update-cli
Dockerfile: update docker CLI to v26.1.0
2024-04-23 12:52:47 +02:00
racequite
147f701bd1 chore: fix function names in comment
Signed-off-by: Rui JingAn <quiterace@gmail.com>
2024-04-23 17:49:41 +08:00
Sebastiaan van Stijn
e3c59640d5 vendor: github.com/Microsoft/go-winio v0.6.2
- fileinfo: internally fix FileBasicInfo memory alignment (fixes compatibility
  with go1.22)

full diff: https://github.com/Microsoft/go-winio/compare/v0.6.1...v0.6.2

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-04-23 11:00:52 +02:00
Sebastiaan van Stijn
2140e7e0f5 vendor: golang.org/x/tools v0.16.0
It's not used in our code, but some dependencies have a "tools.go" to
force it; updating to a version that doesn't depend on golang.org/x/sys/execabs

full diff: https://github.com/golang/tools/compare/v0.14.0...v0.16.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-04-23 11:00:03 +02:00
Sebastiaan van Stijn
85c9900377 vendor: golang.org/x/mod v0.17.0
no changes in vendored codee

full diff: https://github.com/golang/mod/compare/v0.13.0...v0.17.0

- modfile: do not collapse if there are unattached comments within blocks
- modfile: fix crash on AddGoStmt in empty File
- modfile: improve directory path detection and error text consistency
- modfile: use new go version string format in WorkFile.add error
- sumdb: replace globsMatchPath with module.MatchPrefixPatterns
- sumdb/tlog: make NewTiles only generate strictly necessary tiles

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-04-23 10:53:17 +02:00
Paweł Gronowski
e314113ad7 Dockerfile: update docker CLI to v26.1.0
Update the CLI that's used in the dev-container

- full diff: https://github.com/docker/cli/compare/v26.0.0...v26.1.0

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-04-23 10:47:49 +02:00
Sebastiaan van Stijn
df831c943f vendor: github.com/cilium/ebpf v0.12.3
full diff: https://github.com/cilium/ebpf/compare/v0.11.0...v0.12.3

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-04-22 13:52:44 +02:00
imalasong
194cbd6e7d Makefile: refactoring .PHONY
Signed-off-by: xiaochangbai <704566072@qq.com>
2024-04-09 09:26:31 +08:00
Antonio Aguilar
57a12a372f Update GoDoc for ioutils on atomic writers
Unlike its stdlib counterparts, AtomicFileWriter does not take into
consideration umask due to its use of chmod. Failure to recognize this
may cause subtle problems like the one described in #47498.

Therefore the documentation has been updated to let users know that
umask is not taken into consideration when using AtomicFileWriter.

Closes #47516.

Signed-off-by: Antonio Aguilar <antonio@zoftko.com>
2024-04-02 23:27:04 -06:00
avoidaway
98d51b510d chore: remove repetitive words
chore: remove repetitive words

Signed-off-by: avoidaway <cmoman@126.com>
2024-03-30 22:17:47 +08:00
Paweł Gronowski
8bbba6315f API: bump version to 1.46
Docker 26.0 was released with API v1.45, so any change in the API should
now target v1.46.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-03-29 11:07:35 +01:00
Alano Terblanche
80d92fd450 feat: ctx to client API
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
2024-03-22 13:06:43 +01:00
Jonas Geiler
838047a1f5 archive: fix ConvertRead/ConvertWrite functions for rootless docker & native diff overlay
Signed-off-by: Jonas Geiler <git@jonasgeiler.com>
2024-03-22 01:25:21 +01:00
Jonas Geiler
aef6905e01 overlay2: better documentation of user namespace behavior when checking native diff support
Signed-off-by: Jonas Geiler <git@jonasgeiler.com>
2024-03-21 22:17:54 +01:00
Jonas Geiler
f6b80253b8 overlay2: get rid of unnecessary kernel version check
Signed-off-by: Jonas Geiler <git@jonasgeiler.com>
2024-03-21 20:44:44 +01:00
Jonas Geiler
b2fd67de77 overlay2: support rootless native overlay diff in kernel 5.11 and above
Signed-off-by: Jonas Geiler <git@jonasgeiler.com>
2024-03-21 01:40:38 +01:00
Lars Andringa
d4f61f92fd Move StartedAt time to before starting the container
Signed-off-by: Lars Andringa <l.s.andringa@rug.nl>
Signed-off-by: LarsSven <l.s.andringa@rug.nl>

Replaced boolean parameter by IsZero check

Signed-off-by: LarsSven <l.s.andringa@rug.nl>

Separated SetRunning into two functions

Signed-off-by: LarsSven <l.s.andringa@rug.nl>

Apply suggestions from code review

Documentation fixes

Co-authored-by: Paweł Gronowski <me@woland.xyz>
Signed-off-by: LarsSven <l.s.andringa@rug.nl>
2024-03-12 16:20:21 +01:00
1014 changed files with 36605 additions and 14557 deletions

View File

@@ -19,6 +19,8 @@ env:
DOCKER_EXPERIMENTAL: 1
DOCKER_GRAPHDRIVER: ${{ inputs.storage == 'snapshotter' && 'overlayfs' || 'overlay2' }}
TEST_INTEGRATION_USE_SNAPSHOTTER: ${{ inputs.storage == 'snapshotter' && '1' || '' }}
SETUP_BUILDX_VERSION: latest
SETUP_BUILDKIT_IMAGE: moby/buildkit:latest
jobs:
unit:
@@ -35,6 +37,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Build dev image
uses: docker/bake-action@v4
@@ -117,6 +123,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Build dev image
uses: docker/bake-action@v4
@@ -167,6 +177,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Build dev image
uses: docker/bake-action@v4
@@ -221,6 +235,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Build dev image
uses: docker/bake-action@v4
@@ -362,6 +380,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Build dev image
uses: docker/bake-action@v4

View File

@@ -19,7 +19,7 @@ on:
default: false
env:
GO_VERSION: "1.21.9"
GO_VERSION: "1.21.11"
GOTESTLIST_VERSION: v0.3.1
TESTSTAT_VERSION: v0.1.25
WINDOWS_BASE_IMAGE: mcr.microsoft.com/windows/servercore

View File

@@ -21,6 +21,8 @@ env:
PLATFORM: Moby Engine - Nightly
PRODUCT: moby-bin
PACKAGER_NAME: The Moby Project
SETUP_BUILDX_VERSION: latest
SETUP_BUILDKIT_IMAGE: moby/buildkit:latest
jobs:
validate-dco:
@@ -112,6 +114,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Login to Docker Hub
if: github.event_name != 'pull_request' && github.repository == 'moby/moby'
@@ -171,6 +177,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Login to Docker Hub
uses: docker/login-action@v3

View File

@@ -13,8 +13,10 @@ on:
pull_request:
env:
GO_VERSION: "1.21.9"
GO_VERSION: "1.21.11"
DESTDIR: ./build
SETUP_BUILDX_VERSION: latest
SETUP_BUILDKIT_IMAGE: moby/buildkit:latest
jobs:
validate-dco:
@@ -31,6 +33,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Build
uses: docker/bake-action@v4
@@ -105,6 +111,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Download binary artifacts
uses: actions/download-artifact@v4

View File

@@ -14,6 +14,8 @@ on:
env:
DESTDIR: ./build
SETUP_BUILDX_VERSION: latest
SETUP_BUILDKIT_IMAGE: moby/buildkit:latest
jobs:
validate-dco:
@@ -38,6 +40,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Build
uses: docker/bake-action@v4
@@ -96,6 +102,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Build
uses: docker/bake-action@v4

View File

@@ -13,9 +13,11 @@ on:
pull_request:
env:
GO_VERSION: "1.21.9"
GO_VERSION: "1.21.11"
GIT_PAGER: "cat"
PAGER: "cat"
SETUP_BUILDX_VERSION: latest
SETUP_BUILDKIT_IMAGE: moby/buildkit:latest
jobs:
validate-dco:
@@ -44,6 +46,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Build dev image
uses: docker/bake-action@v4
@@ -112,6 +118,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Build dev image
uses: docker/bake-action@v4
@@ -168,6 +178,10 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ env.SETUP_BUILDX_VERSION }}
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
buildkitd-flags: --debug
-
name: Test
uses: docker/bake-action@v4

View File

@@ -38,7 +38,7 @@ linters-settings:
alias:
# Enforce alias to prevent it accidentally being used instead of our
# own errdefs package (or vice-versa).
- pkg: github.com/containerd/containerd/errdefs
- pkg: github.com/containerd/errdefs
alias: cerrdefs
- pkg: github.com/opencontainers/image-spec/specs-go/v1
alias: ocispec
@@ -57,6 +57,10 @@ linters-settings:
desc: Use "gotest.tools/v3/assert" instead
- pkg: "github.com/stretchr/testify/suite"
desc: Do not use
- pkg: github.com/containerd/containerd/errdefs
desc: The errdefs package has moved to a separate module, https://github.com/containerd/errdefs
- pkg: github.com/containerd/containerd/log
desc: The logs package has moved to a separate module, https://github.com/containerd/log
revive:
rules:
# FIXME make sure all packages have a description. Currently, there's many packages without.
@@ -130,6 +134,16 @@ issues:
linters:
- staticcheck
- text: "ineffectual assignment to ctx"
source: "ctx[, ].*=.*\\(ctx[,)]"
linters:
- ineffassign
- text: "SA4006: this value of `ctx` is never used"
source: "ctx[, ].*=.*\\(ctx[,)]"
linters:
- staticcheck
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

View File

@@ -7,6 +7,7 @@
#
# For an explanation of this file format, consult gitmailmap(5).
Aaron Yoshitake <airandfingers@gmail.com>
Aaron L. Xu <liker.xu@foxmail.com>
Aaron L. Xu <liker.xu@foxmail.com> <likexu@harmonycloud.cn>
Aaron Lehmann <alehmann@netflix.com>
@@ -30,9 +31,11 @@ Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp> <suda.akihiro@lab.ntt.co.jp>
Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp> <suda.kyoto@gmail.com>
Akshay Moghe <akshay.moghe@gmail.com>
Alano Terblanche <alano.terblanche@docker.com>
Alano Terblanche <alano.terblanche@docker.com> <18033717+Benehiko@users.noreply.github.com>
Albin Kerouanton <albinker@gmail.com>
Albin Kerouanton <albinker@gmail.com> <albin@akerouanton.name>
Albin Kerouanton <albinker@gmail.com> <557933+akerouanton@users.noreply.github.com>
Albin Kerouanton <albinker@gmail.com> <albin@akerouanton.name>
Aleksa Sarai <asarai@suse.de>
Aleksa Sarai <asarai@suse.de> <asarai@suse.com>
Aleksa Sarai <asarai@suse.de> <cyphar@cyphar.com>
@@ -59,6 +62,8 @@ Allen Sun <allensun.shl@alibaba-inc.com> <allen.sun@daocloud.io>
Allen Sun <allensun.shl@alibaba-inc.com> <shlallen1990@gmail.com>
Anca Iordache <anca.iordache@docker.com>
Andrea Denisse Gómez <crypto.andrea@protonmail.ch>
Andrew Baxter <423qpsxzhh8k3h@s.rendaw.me>
Andrew Baxter <423qpsxzhh8k3h@s.rendaw.me> andrew <>
Andrew Kim <taeyeonkim90@gmail.com>
Andrew Kim <taeyeonkim90@gmail.com> <akim01@fortinet.com>
Andrew Weiss <andrew.weiss@docker.com> <andrew.weiss@microsoft.com>
@@ -119,6 +124,7 @@ Brian Goff <cpuguy83@gmail.com> <bgoff@cpuguy83-mbp.home>
Brian Goff <cpuguy83@gmail.com> <bgoff@cpuguy83-mbp.local>
Brian Goff <cpuguy83@gmail.com> <brian.goff@microsoft.com>
Brian Goff <cpuguy83@gmail.com> <cpuguy@hey.com>
Calvin Liu <flycalvin@qq.com>
Cameron Sparr <gh@sparr.email>
Carlos de Paula <me@carlosedp.com>
Chander Govindarajan <chandergovind@gmail.com>
@@ -130,6 +136,7 @@ Chen Mingjie <chenmingjie0828@163.com>
Chen Qiu <cheney-90@hotmail.com>
Chen Qiu <cheney-90@hotmail.com> <21321229@zju.edu.cn>
Chengfei Shang <cfshang@alauda.io>
Chentianze <cmoman@126.com>
Chris Dias <cdias@microsoft.com>
Chris McKinnel <chris.mckinnel@tangentlabs.co.uk>
Chris Price <cprice@mirantis.com>
@@ -138,6 +145,8 @@ Chris Telfer <ctelfer@docker.com>
Chris Telfer <ctelfer@docker.com> <ctelfer@users.noreply.github.com>
Christopher Biscardi <biscarch@sketcht.com>
Christopher Latham <sudosurootdev@gmail.com>
Christopher Petito <chrisjpetito@gmail.com>
Christopher Petito <chrisjpetito@gmail.com> <47751006+krissetto@users.noreply.github.com>
Christy Norman <christy@linux.vnet.ibm.com>
Chun Chen <ramichen@tencent.com> <chenchun.feed@gmail.com>
Corbin Coleman <corbin.coleman@docker.com>
@@ -341,6 +350,8 @@ John Howard <github@lowenna.com> <john.howard@microsoft.com>
John Howard <github@lowenna.com> <john@lowenna.com>
John Stephens <johnstep@docker.com> <johnstep@users.noreply.github.com>
Jon Surrell <jon.surrell@gmail.com> <jon.surrell@automattic.com>
Jonathan A. Sternberg <jonathansternberg@gmail.com>
Jonathan A. Sternberg <jonathansternberg@gmail.com> <jonathan.sternberg@docker.com>
Jonathan Choy <jonathan.j.choy@gmail.com>
Jonathan Choy <jonathan.j.choy@gmail.com> <oni@tetsujinlabs.com>
Jordan Arentsen <blissdev@gmail.com>
@@ -483,14 +494,14 @@ Mikael Davranche <mikael.davranche@corp.ovh.com> <mikael.davranche@corp.ovh.net>
Mike Casas <mkcsas0@gmail.com> <mikecasas@users.noreply.github.com>
Mike Goelzer <mike.goelzer@docker.com> <mgoelzer@docker.com>
Milas Bowman <devnull@milas.dev>
Milas Bowman <devnull@milas.dev> <milasb@gmail.com>
Milas Bowman <devnull@milas.dev> <milas.bowman@docker.com>
Milas Bowman <devnull@milas.dev> <milasb@gmail.com>
Milind Chawre <milindchawre@gmail.com>
Misty Stanley-Jones <misty@docker.com> <misty@apache.org>
Mohammad Banikazemi <MBanikazemi@gmail.com>
Mohammad Banikazemi <MBanikazemi@gmail.com> <mb@us.ibm.com>
Mohd Sadiq <mohdsadiq058@gmail.com> <mohdsadiq058@gmail.com>
Mohd Sadiq <mohdsadiq058@gmail.com> <42430865+msadiq058@users.noreply.github.com>
Mohd Sadiq <mohdsadiq058@gmail.com> <mohdsadiq058@gmail.com>
Mohit Soni <mosoni@ebay.com> <mohitsoni1989@gmail.com>
Moorthy RS <rsmoorthy@gmail.com> <rsmoorthy@users.noreply.github.com>
Moysés Borges <moysesb@gmail.com>
@@ -515,6 +526,7 @@ Olli Janatuinen <olli.janatuinen@gmail.com> <olljanat@users.noreply.github.com>
Onur Filiz <onur.filiz@microsoft.com>
Onur Filiz <onur.filiz@microsoft.com> <ofiliz@users.noreply.github.com>
Ouyang Liduo <oyld0210@163.com>
Patrick St. laurent <patrick@saint-laurent.us>
Patrick Stapleton <github@gdi2290.com>
Paul Liljenberg <liljenberg.paul@gmail.com> <letters@paulnotcom.se>
Pavel Tikhomirov <ptikhomirov@virtuozzo.com> <ptikhomirov@parallels.com>
@@ -538,6 +550,8 @@ Qin TianHuan <tianhuan@bingotree.cn>
Ray Tsang <rayt@google.com> <saturnism@users.noreply.github.com>
Renaud Gaubert <rgaubert@nvidia.com> <renaud.gaubert@gmail.com>
Richard Scothern <richard.scothern@gmail.com>
Rob Murray <rob.murray@docker.com>
Rob Murray <rob.murray@docker.com> <148866618+robmry@users.noreply.github.com>
Robert Terhaar <rterhaar@atlanticdynamic.com> <robbyt@users.noreply.github.com>
Roberto G. Hashioka <roberto.hashioka@docker.com> <roberto_hashioka@hotmail.com>
Roberto Muñoz Fernández <robertomf@gmail.com> <roberto.munoz.fernandez.contractor@bbva.com>
@@ -548,6 +562,7 @@ Rongxiang Song <tinysong1226@gmail.com>
Rony Weng <ronyweng@synology.com>
Ross Boucher <rboucher@gmail.com>
Rui Cao <ruicao@alauda.io>
Rui JingAn <quiterace@gmail.com>
Runshen Zhu <runshen.zhu@gmail.com>
Ryan Stelly <ryan.stelly@live.com>
Ryoga Saito <contact@proelbtn.com>

20
AUTHORS
View File

@@ -10,6 +10,7 @@ Aaron Huslage <huslage@gmail.com>
Aaron L. Xu <liker.xu@foxmail.com>
Aaron Lehmann <alehmann@netflix.com>
Aaron Welch <welch@packet.net>
Aaron Yoshitake <airandfingers@gmail.com>
Abel Muiño <amuino@gmail.com>
Abhijeet Kasurde <akasurde@redhat.com>
Abhinandan Prativadi <aprativadi@gmail.com>
@@ -62,6 +63,7 @@ alambike <alambike@gmail.com>
Alan Hoyle <alan@alanhoyle.com>
Alan Scherger <flyinprogrammer@gmail.com>
Alan Thompson <cloojure@gmail.com>
Alano Terblanche <alano.terblanche@docker.com>
Albert Callarisa <shark234@gmail.com>
Albert Zhang <zhgwenming@gmail.com>
Albin Kerouanton <albinker@gmail.com>
@@ -141,6 +143,7 @@ Andreas Tiefenthaler <at@an-ti.eu>
Andrei Gherzan <andrei@resin.io>
Andrei Ushakov <aushakov@netflix.com>
Andrei Vagin <avagin@gmail.com>
Andrew Baxter <423qpsxzhh8k3h@s.rendaw.me>
Andrew C. Bodine <acbodine@us.ibm.com>
Andrew Clay Shafer <andrewcshafer@gmail.com>
Andrew Duckworth <grillopress@gmail.com>
@@ -193,6 +196,7 @@ Anton Löfgren <anton.lofgren@gmail.com>
Anton Nikitin <anton.k.nikitin@gmail.com>
Anton Polonskiy <anton.polonskiy@gmail.com>
Anton Tiurin <noxiouz@yandex.ru>
Antonio Aguilar <antonio@zoftko.com>
Antonio Murdaca <antonio.murdaca@gmail.com>
Antonis Kalipetis <akalipetis@gmail.com>
Antony Messerli <amesserl@rackspace.com>
@@ -221,7 +225,6 @@ Avi Das <andas222@gmail.com>
Avi Kivity <avi@scylladb.com>
Avi Miller <avi.miller@oracle.com>
Avi Vaid <avaid1996@gmail.com>
ayoshitake <airandfingers@gmail.com>
Azat Khuyiyakhmetov <shadow_uz@mail.ru>
Bao Yonglei <baoyonglei@huawei.com>
Bardia Keyoumarsi <bkeyouma@ucsc.edu>
@@ -316,6 +319,7 @@ Burke Libbey <burke@libbey.me>
Byung Kang <byung.kang.ctr@amrdec.army.mil>
Caleb Spare <cespare@gmail.com>
Calen Pennington <cale@edx.org>
Calvin Liu <flycalvin@qq.com>
Cameron Boehmer <cameron.boehmer@gmail.com>
Cameron Sparr <gh@sparr.email>
Cameron Spear <cameronspear@gmail.com>
@@ -362,6 +366,7 @@ Chen Qiu <cheney-90@hotmail.com>
Cheng-mean Liu <soccerl@microsoft.com>
Chengfei Shang <cfshang@alauda.io>
Chengguang Xu <cgxu519@gmx.com>
Chentianze <cmoman@126.com>
Chenyang Yan <memory.yancy@gmail.com>
chenyuzhu <chenyuzhi@oschina.cn>
Chetan Birajdar <birajdar.chetan@gmail.com>
@@ -409,6 +414,7 @@ Christopher Crone <christopher.crone@docker.com>
Christopher Currie <codemonkey+github@gmail.com>
Christopher Jones <tophj@linux.vnet.ibm.com>
Christopher Latham <sudosurootdev@gmail.com>
Christopher Petito <chrisjpetito@gmail.com>
Christopher Rigor <crigor@gmail.com>
Christy Norman <christy@linux.vnet.ibm.com>
Chun Chen <ramichen@tencent.com>
@@ -777,6 +783,7 @@ Gabriel L. Somlo <gsomlo@gmail.com>
Gabriel Linder <linder.gabriel@gmail.com>
Gabriel Monroy <gabriel@opdemand.com>
Gabriel Nicolas Avellaneda <avellaneda.gabriel@gmail.com>
Gabriel Tomitsuka <gabriel@tomitsuka.com>
Gaetan de Villele <gdevillele@gmail.com>
Galen Sampson <galen.sampson@gmail.com>
Gang Qiao <qiaohai8866@gmail.com>
@@ -792,6 +799,7 @@ Geoff Levand <geoff@infradead.org>
Geoffrey Bachelet <grosfrais@gmail.com>
Geon Kim <geon0250@gmail.com>
George Kontridze <george@bugsnag.com>
George Ma <mayangang@outlook.com>
George MacRorie <gmacr31@gmail.com>
George Xie <georgexsh@gmail.com>
Georgi Hristozov <georgi@forkbomb.nl>
@@ -913,6 +921,7 @@ Illo Abdulrahim <abdulrahim.illo@nokia.com>
Ilya Dmitrichenko <errordeveloper@gmail.com>
Ilya Gusev <mail@igusev.ru>
Ilya Khlopotov <ilya.khlopotov@gmail.com>
imalasong <2879499479@qq.com>
imre Fitos <imre.fitos+github@gmail.com>
inglesp <peter.inglesby@gmail.com>
Ingo Gottwald <in.gottwald@gmail.com>
@@ -930,6 +939,7 @@ J Bruni <joaohbruni@yahoo.com.br>
J. Nunn <jbnunn@gmail.com>
Jack Danger Canty <jackdanger@squareup.com>
Jack Laxson <jackjrabbit@gmail.com>
Jack Walker <90711509+j2walker@users.noreply.github.com>
Jacob Atzen <jacob@jacobatzen.dk>
Jacob Edelman <edelman.jd@gmail.com>
Jacob Tomlinson <jacob@tom.linson.uk>
@@ -989,6 +999,7 @@ Jason Shepherd <jason@jasonshepherd.net>
Jason Smith <jasonrichardsmith@gmail.com>
Jason Sommer <jsdirv@gmail.com>
Jason Stangroome <jason@codeassassin.com>
Jasper Siepkes <siepkes@serviceplanet.nl>
Javier Bassi <javierbassi@gmail.com>
jaxgeller <jacksongeller@gmail.com>
Jay <teguhwpurwanto@gmail.com>
@@ -1100,6 +1111,7 @@ Jon Johnson <jonjohnson@google.com>
Jon Surrell <jon.surrell@gmail.com>
Jon Wedaman <jweede@gmail.com>
Jonas Dohse <jonas@dohse.ch>
Jonas Geiler <git@jonasgeiler.com>
Jonas Heinrich <Jonas@JonasHeinrich.com>
Jonas Pfenniger <jonas@pfenniger.name>
Jonathan A. Schweder <jonathanschweder@gmail.com>
@@ -1267,6 +1279,7 @@ Lakshan Perera <lakshan@laktek.com>
Lalatendu Mohanty <lmohanty@redhat.com>
Lance Chen <cyen0312@gmail.com>
Lance Kinley <lkinley@loyaltymethods.com>
Lars Andringa <l.s.andringa@rug.nl>
Lars Butler <Lars.Butler@gmail.com>
Lars Kellogg-Stedman <lars@redhat.com>
Lars R. Damerow <lars@pixar.com>
@@ -1673,6 +1686,7 @@ Patrick Böänziger <patrick.baenziger@bsi-software.com>
Patrick Devine <patrick.devine@docker.com>
Patrick Haas <patrickhaas@google.com>
Patrick Hemmer <patrick.hemmer@gmail.com>
Patrick St. laurent <patrick@saint-laurent.us>
Patrick Stapleton <github@gdi2290.com>
Patrik Cyvoct <patrik@ptrk.io>
pattichen <craftsbear@gmail.com>
@@ -1878,6 +1892,7 @@ Royce Remer <royceremer@gmail.com>
Rozhnov Alexandr <nox73@ya.ru>
Rudolph Gottesheim <r.gottesheim@loot.at>
Rui Cao <ruicao@alauda.io>
Rui JingAn <quiterace@gmail.com>
Rui Lopes <rgl@ruilopes.com>
Ruilin Li <liruilin4@huawei.com>
Runshen Zhu <runshen.zhu@gmail.com>
@@ -2184,6 +2199,7 @@ Tomek Mańko <tomek.manko@railgun-solutions.com>
Tommaso Visconti <tommaso.visconti@gmail.com>
Tomoya Tabuchi <t@tomoyat1.com>
Tomáš Hrčka <thrcka@redhat.com>
Tomáš Virtus <nechtom@gmail.com>
tonic <tonicbupt@gmail.com>
Tonny Xu <tonny.xu@gmail.com>
Tony Abboud <tdabboud@hotmail.com>
@@ -2228,6 +2244,7 @@ Victor I. Wood <viw@t2am.com>
Victor Lyuboslavsky <victor@victoreda.com>
Victor Marmol <vmarmol@google.com>
Victor Palma <palma.victor@gmail.com>
Victor Toni <victor.toni@gmail.com>
Victor Vieux <victor.vieux@docker.com>
Victoria Bialas <victoria.bialas@docker.com>
Vijaya Kumar K <vijayak@caviumnetworks.com>
@@ -2279,6 +2296,7 @@ Wassim Dhif <wassimdhif@gmail.com>
Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Wayne Chang <wayne@neverfear.org>
Wayne Song <wsong@docker.com>
weebney <weebney@gmail.com>
Weerasak Chongnguluam <singpor@gmail.com>
Wei Fu <fuweid89@gmail.com>
Wei Wu <wuwei4455@gmail.com>

View File

@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.7
ARG GO_VERSION=1.21.9
ARG GO_VERSION=1.21.11
ARG BASE_DEBIAN_DISTRO="bookworm"
ARG GOLANG_IMAGE="golang:${GO_VERSION}-${BASE_DEBIAN_DISTRO}"
ARG XX_VERSION=1.4.0
@@ -8,12 +8,12 @@ ARG XX_VERSION=1.4.0
ARG VPNKIT_VERSION=0.5.0
ARG DOCKERCLI_REPOSITORY="https://github.com/docker/cli.git"
ARG DOCKERCLI_VERSION=v26.0.0
ARG DOCKERCLI_VERSION=v26.1.0
# cli version used for integration-cli tests
ARG DOCKERCLI_INTEGRATION_REPOSITORY="https://github.com/docker/cli.git"
ARG DOCKERCLI_INTEGRATION_VERSION=v17.06.2-ce
ARG BUILDX_VERSION=0.13.1
ARG COMPOSE_VERSION=v2.25.0
ARG BUILDX_VERSION=0.15.1
ARG COMPOSE_VERSION=v2.27.1
ARG SYSTEMD="false"
ARG DOCKER_STATIC=1
@@ -196,7 +196,7 @@ RUN git init . && git remote add origin "https://github.com/containerd/container
# When updating the binary version you may also need to update the vendor
# version to pick up bug fixes or new APIs, however, usually the Go packages
# are built from a commit from the master branch.
ARG CONTAINERD_VERSION=v1.7.15
ARG CONTAINERD_VERSION=v1.7.18
RUN git fetch -q --depth 1 origin "${CONTAINERD_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
FROM base AS containerd-build
@@ -229,7 +229,7 @@ FROM binary-dummy AS containerd-windows
FROM containerd-${TARGETOS} AS containerd
FROM base AS golangci_lint
ARG GOLANGCI_LINT_VERSION=v1.55.2
ARG GOLANGCI_LINT_VERSION=v1.59.1
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
GOBIN=/build/ GO111MODULE=on go install "github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}" \
@@ -287,7 +287,7 @@ RUN git init . && git remote add origin "https://github.com/opencontainers/runc.
# that is used. If you need to update runc, open a pull request in the containerd
# project first, and update both after that is merged. When updating RUNC_VERSION,
# consider updating runc in vendor.mod accordingly.
ARG RUNC_VERSION=v1.1.12
ARG RUNC_VERSION=v1.1.13
RUN git fetch -q --depth 1 origin "${RUNC_VERSION}" +refs/tags/*:refs/tags/* && git checkout -q FETCH_HEAD
FROM base AS runc-build

View File

@@ -5,7 +5,7 @@
# This represents the bare minimum required to build and test Docker.
ARG GO_VERSION=1.21.9
ARG GO_VERSION=1.21.11
ARG BASE_DEBIAN_DISTRO="bookworm"
ARG GOLANG_IMAGE="golang:${GO_VERSION}-${BASE_DEBIAN_DISTRO}"

View File

@@ -161,10 +161,10 @@ FROM ${WINDOWS_BASE_IMAGE}:${WINDOWS_BASE_IMAGE_TAG}
# Use PowerShell as the default shell
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ARG GO_VERSION=1.21.9
ARG GO_VERSION=1.21.11
ARG GOTESTSUM_VERSION=v1.8.2
ARG GOWINRES_VERSION=v0.3.1
ARG CONTAINERD_VERSION=v1.7.15
ARG CONTAINERD_VERSION=v1.7.18
# Environment variable notes:
# - GO_VERSION must be consistent with 'Dockerfile' used by Linux.

View File

@@ -38,6 +38,7 @@
"laurazard",
"mhbauer",
"neersighted",
"robmry",
"rumpl",
"runcom",
"samuelkarp",
@@ -75,7 +76,6 @@
"olljanat",
"programmerq",
"ripcurld",
"robmry",
"sam-thibault",
"samwhited",
"thajeztah"

View File

@@ -1,5 +1,3 @@
.PHONY: all binary dynbinary build cross help install manpages run shell test test-docker-py test-integration test-unit validate validate-% win
DOCKER ?= docker
BUILDX ?= $(DOCKER) buildx
@@ -157,15 +155,19 @@ BAKE_CMD := $(BUILDX) bake
default: binary
.PHONY: all
all: build ## validate all checks, build linux binaries, run all tests,\ncross build non-linux binaries, and generate archives
$(DOCKER_RUN_DOCKER) bash -c 'hack/validate/default && hack/make.sh'
.PHONY: binary
binary: bundles ## build statically linked linux binaries
$(BAKE_CMD) binary
.PHONY: dynbinary
dynbinary: bundles ## build dynamically linked linux binaries
$(BAKE_CMD) dynbinary
.PHONY: cross
cross: bundles ## cross build the binaries
$(BAKE_CMD) binary-cross
@@ -179,12 +181,15 @@ clean: clean-cache
clean-cache: ## remove the docker volumes that are used for caching in the dev-container
docker volume rm -f docker-dev-cache docker-mod-cache
.PHONY: help
help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: install
install: ## install the linux binaries
KEEPBUNDLE=1 hack/make.sh install-binary
.PHONY: run
run: build ## run the docker daemon in a container
$(DOCKER_RUN_DOCKER) sh -c "KEEPBUNDLE=1 hack/make.sh install-binary run"
@@ -197,17 +202,22 @@ endif
build: bundles
$(BUILD_CMD) $(BUILD_OPTS) $(shell_target) --load -t "$(DOCKER_IMAGE)" .
.PHONY: shell
shell: build ## start a shell inside the build env
$(DOCKER_RUN_DOCKER) bash
.PHONY: test
test: build test-unit ## run the unit, integration and docker-py tests
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration test-docker-py
.PHONY: test-docker-py
test-docker-py: build ## run the docker-py tests
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-docker-py
.PHONY: test-integration-cli
test-integration-cli: test-integration ## (DEPRECATED) use test-integration
.PHONY: test-integration
ifneq ($(and $(TEST_SKIP_INTEGRATION),$(TEST_SKIP_INTEGRATION_CLI)),)
test-integration:
@echo Both integrations suites skipped per environment variables
@@ -216,23 +226,29 @@ test-integration: build ## run the integration tests
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration
endif
.PHONY: test-integration-flaky
test-integration-flaky: build ## run the stress test for all new integration tests
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary test-integration-flaky
.PHONY: test-unit
test-unit: build ## run the unit tests
$(DOCKER_RUN_DOCKER) hack/test/unit
.PHONY: validate
validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isolation, golint, tests, tomls, go vet and vendor
$(DOCKER_RUN_DOCKER) hack/validate/all
.PHONY: validate-generate-files
validate-generate-files:
$(BUILD_CMD) --target "validate" \
--output "type=cacheonly" \
--file "./hack/dockerfiles/generate-files.Dockerfile" .
.PHONY: validate-%
validate-%: build ## validate specific check
$(DOCKER_RUN_DOCKER) hack/validate/$*
.PHONY: win
win: bundles ## cross build the binary for windows
$(BAKE_CMD) --set *.platform=windows/amd64 binary

View File

@@ -3,7 +3,7 @@ package api // import "github.com/docker/docker/api"
// Common constants for daemon and client.
const (
// DefaultVersion of the current REST API.
DefaultVersion = "1.45"
DefaultVersion = "1.46"
// MinSupportedAPIVersion is the minimum API version that can be supported
// by the API server, specified as "major.minor". Note that the daemon

View File

@@ -5,7 +5,7 @@ import (
"fmt"
"net/http"
cerrdefs "github.com/containerd/containerd/errdefs"
cerrdefs "github.com/containerd/errdefs"
"github.com/containerd/log"
"github.com/docker/distribution/registry/api/errcode"
"github.com/docker/docker/errdefs"
@@ -24,42 +24,37 @@ func FromError(err error) int {
return http.StatusInternalServerError
}
var statusCode int
// Stop right there
// Are you sure you should be adding a new error class here? Do one of the existing ones work?
// Note that the below functions are already checking the error causal chain for matches.
switch {
case errdefs.IsNotFound(err):
statusCode = http.StatusNotFound
return http.StatusNotFound
case errdefs.IsInvalidParameter(err):
statusCode = http.StatusBadRequest
return http.StatusBadRequest
case errdefs.IsConflict(err):
statusCode = http.StatusConflict
return http.StatusConflict
case errdefs.IsUnauthorized(err):
statusCode = http.StatusUnauthorized
return http.StatusUnauthorized
case errdefs.IsUnavailable(err):
statusCode = http.StatusServiceUnavailable
return http.StatusServiceUnavailable
case errdefs.IsForbidden(err):
statusCode = http.StatusForbidden
return http.StatusForbidden
case errdefs.IsNotModified(err):
statusCode = http.StatusNotModified
return http.StatusNotModified
case errdefs.IsNotImplemented(err):
statusCode = http.StatusNotImplemented
return http.StatusNotImplemented
case errdefs.IsSystem(err) || errdefs.IsUnknown(err) || errdefs.IsDataLoss(err) || errdefs.IsDeadline(err) || errdefs.IsCancelled(err):
statusCode = http.StatusInternalServerError
return http.StatusInternalServerError
default:
statusCode = statusCodeFromGRPCError(err)
if statusCode != http.StatusInternalServerError {
if statusCode := statusCodeFromGRPCError(err); statusCode != http.StatusInternalServerError {
return statusCode
}
statusCode = statusCodeFromContainerdError(err)
if statusCode != http.StatusInternalServerError {
if statusCode := statusCodeFromContainerdError(err); statusCode != http.StatusInternalServerError {
return statusCode
}
statusCode = statusCodeFromDistributionError(err)
if statusCode != http.StatusInternalServerError {
if statusCode := statusCodeFromDistributionError(err); statusCode != http.StatusInternalServerError {
return statusCode
}
if e, ok := err.(causer); ok {
@@ -71,13 +66,9 @@ func FromError(err error) int {
"error": err,
"error_type": fmt.Sprintf("%T", err),
}).Debug("FIXME: Got an API for which error does not match any expected type!!!")
}
if statusCode == 0 {
statusCode = http.StatusInternalServerError
return http.StatusInternalServerError
}
return statusCode
}
// statusCodeFromGRPCError returns status code according to gRPC error

View File

@@ -1,12 +1,17 @@
package httputils // import "github.com/docker/docker/api/server/httputils"
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"
"github.com/distribution/reference"
"github.com/docker/docker/errdefs"
"github.com/pkg/errors"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// BoolValue transforms a form value in different formats into a boolean type.
@@ -109,3 +114,24 @@ func ArchiveFormValues(r *http.Request, vars map[string]string) (ArchiveOptions,
}
return ArchiveOptions{name, path}, nil
}
// DecodePlatform decodes the OCI platform JSON string into a Platform struct.
func DecodePlatform(platformJSON string) (*ocispec.Platform, error) {
var p ocispec.Platform
if err := json.Unmarshal([]byte(platformJSON), &p); err != nil {
return nil, errdefs.InvalidParameter(errors.Wrap(err, "failed to parse platform"))
}
hasAnyOptional := (p.Variant != "" || p.OSVersion != "" || len(p.OSFeatures) > 0)
if p.OS == "" && p.Architecture == "" && hasAnyOptional {
return nil, errdefs.InvalidParameter(errors.New("optional platform fields provided, but OS and Architecture are missing"))
}
if p.OS == "" || p.Architecture == "" {
return nil, errdefs.InvalidParameter(errors.New("both OS and Architecture must be provided"))
}
return &p, nil
}

View File

@@ -1,9 +1,16 @@
package httputils // import "github.com/docker/docker/api/server/httputils"
import (
"encoding/json"
"net/http"
"net/url"
"testing"
"github.com/containerd/containerd/platforms"
"github.com/docker/docker/errdefs"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"gotest.tools/v3/assert"
)
func TestBoolValue(t *testing.T) {
@@ -103,3 +110,23 @@ func TestInt64ValueOrDefaultWithError(t *testing.T) {
t.Fatal("Expected an error.")
}
}
func TestParsePlatformInvalid(t *testing.T) {
for _, tc := range []ocispec.Platform{
{
OSVersion: "1.2.3",
OSFeatures: []string{"a", "b"},
},
{OSVersion: "12.0"},
{OS: "linux"},
{Architecture: "amd64"},
} {
t.Run(platforms.Format(tc), func(t *testing.T) {
js, err := json.Marshal(tc)
assert.NilError(t, err)
_, err = DecodePlatform(string(js))
assert.Check(t, errdefs.IsInvalidParameter(err))
})
}
}

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"net/http"
"net/url"
"sort"
@@ -16,7 +17,11 @@ import (
// WriteLogStream writes an encoded byte stream of log messages from the
// messages channel, multiplexing them with a stdcopy.Writer if mux is true
func WriteLogStream(_ context.Context, w io.Writer, msgs <-chan *backend.LogMessage, config *container.LogsOptions, mux bool) {
func WriteLogStream(_ context.Context, w http.ResponseWriter, msgs <-chan *backend.LogMessage, config *container.LogsOptions, mux bool) {
// See https://github.com/moby/moby/issues/47448
// Trigger headers to be written immediately.
w.WriteHeader(http.StatusOK)
wf := ioutils.NewWriteFlusher(w)
defer wf.Close()

View File

@@ -10,11 +10,15 @@ import (
// CORSMiddleware injects CORS headers to each request
// when it's configured.
//
// Deprecated: CORS headers should not be set on the API. This feature will be removed in the next release.
type CORSMiddleware struct {
defaultHeaders string
}
// NewCORSMiddleware creates a new CORSMiddleware with default headers.
//
// Deprecated: CORS headers should not be set on the API. This feature will be removed in the next release.
func NewCORSMiddleware(d string) CORSMiddleware {
return CORSMiddleware{defaultHeaders: d}
}

View File

@@ -25,7 +25,6 @@ import (
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
units "github.com/docker/go-units"
"github.com/pkg/errors"
)
@@ -105,7 +104,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
}
if ulimitsJSON := r.FormValue("ulimits"); ulimitsJSON != "" {
buildUlimits := []*units.Ulimit{}
buildUlimits := []*container.Ulimit{}
if err := json.Unmarshal([]byte(ulimitsJSON), &buildUlimits); err != nil {
return nil, invalidParam{errors.Wrap(err, "error reading ulimit settings")}
}

View File

@@ -14,19 +14,19 @@ import (
// execBackend includes functions to implement to provide exec functionality.
type execBackend interface {
ContainerExecCreate(name string, config *types.ExecConfig) (string, error)
ContainerExecCreate(name string, options *container.ExecOptions) (string, error)
ContainerExecInspect(id string) (*backend.ExecInspect, error)
ContainerExecResize(name string, height, width int) error
ContainerExecStart(ctx context.Context, name string, options container.ExecStartOptions) error
ContainerExecStart(ctx context.Context, name string, options backend.ExecStartConfig) error
ExecExists(name string) (bool, error)
}
// copyBackend includes functions to implement to provide container copy functionality.
type copyBackend interface {
ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error)
ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *container.PathStat, err error)
ContainerExport(ctx context.Context, name string, out io.Writer) error
ContainerExtractToDir(name, path string, copyUIDGID, noOverwriteDirNonDir bool, content io.Reader) error
ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error)
ContainerStatPath(name string, path string) (stat *container.PathStat, err error)
}
// stateBackend includes functions to implement to provide container state lifecycle functionality.
@@ -62,7 +62,7 @@ type attachBackend interface {
// systemBackend includes functions to implement to provide system wide containers functionality
type systemBackend interface {
ContainersPrune(ctx context.Context, pruneFilters filters.Args) (*types.ContainersPruneReport, error)
ContainersPrune(ctx context.Context, pruneFilters filters.Args) (*container.PruneReport, error)
}
type commitBackend interface {

View File

@@ -22,11 +22,14 @@ import (
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/versions"
containerpkg "github.com/docker/docker/container"
networkSettings "github.com/docker/docker/daemon/network"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/libnetwork/netlabel"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/runconfig"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"go.opentelemetry.io/otel"
"golang.org/x/net/websocket"
)
@@ -39,6 +42,13 @@ func (s *containerRouter) postCommit(ctx context.Context, w http.ResponseWriter,
return err
}
// FIXME(thaJeztah): change this to unmarshal just [container.Config]:
// The commit endpoint accepts a [container.Config], but the decoder uses a
// [container.CreateRequest], which is a superset, and also contains
// [container.HostConfig] and [network.NetworkConfig]. Those structs
// are discarded here, but decoder.DecodeConfig also performs validation,
// so a request containing those additional fields would result in a
// validation error.
config, _, _, err := s.decoder.DecodeConfig(r.Body)
if err != nil && !errors.Is(err, io.EOF) { // Do not fail if body is empty.
return err
@@ -94,6 +104,15 @@ func (s *containerRouter) getContainersJSON(ctx context.Context, w http.Response
return err
}
version := httputils.VersionFromContext(ctx)
if versions.LessThan(version, "1.46") {
for _, c := range containers {
// Ignore HostConfig.Annotations because it was added in API v1.46.
c.HostConfig.Annotations = nil
}
}
return httputils.WriteJSON(w, http.StatusOK, containers)
}
@@ -112,9 +131,18 @@ func (s *containerRouter) getContainersStats(ctx context.Context, w http.Respons
}
return s.backend.ContainerStats(ctx, vars["name"], &backend.ContainerStatsConfig{
Stream: stream,
OneShot: oneShot,
OutStream: w,
Stream: stream,
OneShot: oneShot,
OutStream: func() io.Writer {
// Assume that when this is called the request is OK.
w.WriteHeader(http.StatusOK)
if !stream {
return w
}
wf := ioutils.NewWriteFlusher(w)
wf.Flush()
return wf
},
})
}
@@ -169,6 +197,9 @@ func (s *containerRouter) getContainersExport(ctx context.Context, w http.Respon
}
func (s *containerRouter) postContainersStart(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
ctx, span := otel.Tracer("").Start(ctx, "containerRouter.postContainersStart")
defer span.End()
// If contentLength is -1, we can assumed chunked encoding
// or more technically that the length is unknown
// https://golang.org/src/pkg/net/http/request.go#L139
@@ -471,7 +502,7 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo
// Note that this is not the only place where this conversion has to be
// done (as there are various other places where containers get created).
if hostConfig.NetworkMode == "" || hostConfig.NetworkMode.IsDefault() {
hostConfig.NetworkMode = runconfig.DefaultDaemonNetworkMode()
hostConfig.NetworkMode = networkSettings.DefaultNetwork
if nw, ok := networkingConfig.EndpointsConfig[network.NetworkDefault]; ok {
networkingConfig.EndpointsConfig[hostConfig.NetworkMode.NetworkName()] = nw
delete(networkingConfig.EndpointsConfig, network.NetworkDefault)
@@ -619,6 +650,12 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo
warnings = append(warnings, warn)
}
if warn, err := handleSysctlBC(hostConfig, networkingConfig, version); err != nil {
return err
} else if warn != "" {
warnings = append(warnings, warn)
}
if hostConfig.PidsLimit != nil && *hostConfig.PidsLimit <= 0 {
// Don't set a limit if either no limit was specified, or "unlimited" was
// explicitly set.
@@ -662,23 +699,11 @@ func handleMACAddressBC(config *container.Config, hostConfig *container.HostConf
return "", runconfig.ErrConflictContainerNetworkAndMac
}
// There cannot be more than one entry in EndpointsConfig with API < 1.44.
// If there's no EndpointsConfig, create a place to store the configured address. It is
// safe to use NetworkMode as the network name, whether it's a name or id/short-id, as
// it will be normalised later and there is no other EndpointSettings object that might
// refer to this network/endpoint.
if len(networkingConfig.EndpointsConfig) == 0 {
nwName := hostConfig.NetworkMode.NetworkName()
networkingConfig.EndpointsConfig[nwName] = &network.EndpointSettings{}
}
// There's exactly one network in EndpointsConfig, either from the API or just-created.
// Migrate the container-wide setting to it.
// No need to check for a match between NetworkMode and the names/ids in EndpointsConfig,
// the old version of the API would have applied the address to this network anyway.
for _, ep := range networkingConfig.EndpointsConfig {
ep.MacAddress = deprecatedMacAddress
epConfig, err := epConfigForNetMode(version, hostConfig.NetworkMode, networkingConfig)
if err != nil {
return "", err
}
epConfig.MacAddress = deprecatedMacAddress
return "", nil
}
@@ -688,31 +713,16 @@ func handleMACAddressBC(config *container.Config, hostConfig *container.HostConf
}
var warning string
if hostConfig.NetworkMode.IsBridge() || hostConfig.NetworkMode.IsUserDefined() {
nwName := hostConfig.NetworkMode.NetworkName()
// If there's no endpoint config, create a place to store the configured address.
if len(networkingConfig.EndpointsConfig) == 0 {
networkingConfig.EndpointsConfig[nwName] = &network.EndpointSettings{
MacAddress: deprecatedMacAddress,
}
} else {
// There is existing endpoint config - if it's not indexed by NetworkMode.Name(), we
// can't tell which network the container-wide settings was intended for. NetworkMode,
// the keys in EndpointsConfig and the NetworkID in EndpointsConfig may mix network
// name/id/short-id. It's not safe to create EndpointsConfig under the NetworkMode
// name to store the container-wide MAC address, because that may result in two sets
// of EndpointsConfig for the same network and one set will be discarded later. So,
// reject the request ...
ep, ok := networkingConfig.EndpointsConfig[nwName]
if !ok {
return "", errdefs.InvalidParameter(errors.New("if a container-wide MAC address is supplied, HostConfig.NetworkMode must match the identity of a network in NetworkSettings.Networks"))
}
// ep is the endpoint that needs the container-wide MAC address; migrate the address
// to it, or bail out if there's a mismatch.
if ep.MacAddress == "" {
ep.MacAddress = deprecatedMacAddress
} else if ep.MacAddress != deprecatedMacAddress {
return "", errdefs.InvalidParameter(errors.New("the container-wide MAC address must match the endpoint-specific MAC address for the main network, or be left empty"))
}
ep, err := epConfigForNetMode(version, hostConfig.NetworkMode, networkingConfig)
if err != nil {
return "", errors.Wrap(err, "unable to migrate container-wide MAC address to a specific network")
}
// ep is the endpoint that needs the container-wide MAC address; migrate the address
// to it, or bail out if there's a mismatch.
if ep.MacAddress == "" {
ep.MacAddress = deprecatedMacAddress
} else if ep.MacAddress != deprecatedMacAddress {
return "", errdefs.InvalidParameter(errors.New("the container-wide MAC address must match the endpoint-specific MAC address for the main network, or be left empty"))
}
}
warning = "The container-wide MacAddress field is now deprecated. It should be specified in EndpointsConfig instead."
@@ -721,6 +731,146 @@ func handleMACAddressBC(config *container.Config, hostConfig *container.HostConf
return warning, nil
}
// handleSysctlBC migrates top level network endpoint-specific '--sysctl'
// settings to an DriverOpts for an endpoint. This is necessary because sysctls
// are applied during container task creation, but sysctls that name an interface
// (for example 'net.ipv6.conf.eth0.forwarding') cannot be applied until the
// interface has been created. So, these settings are removed from hostConfig.Sysctls
// and added to DriverOpts[netlabel.EndpointSysctls].
//
// Because interface names ('ethN') are allocated sequentially, and the order of
// network connections is not deterministic on container restart, only 'eth0'
// would work reliably in a top-level '--sysctl' option, and then only when
// there's a single initial network connection. So, settings for 'eth0' are
// migrated to the primary interface, identified by 'hostConfig.NetworkMode'.
// Settings for other interfaces are treated as errors.
//
// In the DriverOpts, because the interface name cannot be determined in advance, the
// interface name is replaced by "IFNAME". For example, 'net.ipv6.conf.eth0.forwarding'
// becomes 'net.ipv6.conf.IFNAME.forwarding'. The value in DriverOpts is a
// comma-separated list.
//
// A warning is generated when settings are migrated.
func handleSysctlBC(
hostConfig *container.HostConfig,
netConfig *network.NetworkingConfig,
version string,
) (string, error) {
if !hostConfig.NetworkMode.IsPrivate() {
return "", nil
}
var ep *network.EndpointSettings
var toDelete []string
var netIfSysctls []string
for k, v := range hostConfig.Sysctls {
// If the sysctl name matches "net.*.*.eth0.*" ...
if spl := strings.SplitN(k, ".", 5); len(spl) == 5 && spl[0] == "net" && strings.HasPrefix(spl[3], "eth") {
netIfSysctl := fmt.Sprintf("net.%s.%s.IFNAME.%s=%s", spl[1], spl[2], spl[4], v)
// Find the EndpointConfig to migrate settings to, if not already found.
if ep == nil {
// Per-endpoint sysctls were introduced in API version 1.46. Migration is
// needed, but refuse to do it automatically for newer versions of the API.
if versions.GreaterThan(version, "1.46") {
return "", fmt.Errorf("interface specific sysctl setting %q must be supplied using driver option '%s'",
k, netlabel.EndpointSysctls)
}
var err error
ep, err = epConfigForNetMode(version, hostConfig.NetworkMode, netConfig)
if err != nil {
return "", fmt.Errorf("unable to find a network for sysctl %s: %w", k, err)
}
}
// Only try to migrate settings for "eth0", anything else would always
// have behaved unpredictably.
if spl[3] != "eth0" {
return "", fmt.Errorf(`unable to determine network endpoint for sysctl %s, use driver option '%s' to set per-interface sysctls`,
k, netlabel.EndpointSysctls)
}
// Prepare the migration.
toDelete = append(toDelete, k)
netIfSysctls = append(netIfSysctls, netIfSysctl)
}
}
if ep == nil {
return "", nil
}
newDriverOpt := strings.Join(netIfSysctls, ",")
warning := fmt.Sprintf(`Migrated sysctl %q to DriverOpts{%q:%q}.`,
strings.Join(toDelete, ","),
netlabel.EndpointSysctls, newDriverOpt)
// Append existing per-endpoint sysctls to the migrated sysctls (give priority
// to per-endpoint settings).
if ep.DriverOpts == nil {
ep.DriverOpts = map[string]string{}
}
if oldDriverOpt, ok := ep.DriverOpts[netlabel.EndpointSysctls]; ok {
newDriverOpt += "," + oldDriverOpt
}
ep.DriverOpts[netlabel.EndpointSysctls] = newDriverOpt
// Delete migrated settings from the top-level sysctls.
for _, k := range toDelete {
delete(hostConfig.Sysctls, k)
}
return warning, nil
}
// epConfigForNetMode finds, or creates, an entry in netConfig.EndpointsConfig
// corresponding to nwMode.
//
// nwMode.NetworkName() may be the network's name, its id, or its short-id.
//
// The corresponding endpoint in netConfig.EndpointsConfig may be keyed on a
// different one of name/id/short-id. If there's any ambiguity (there are
// endpoints but the names don't match), return an error and do not create a new
// endpoint, because it might be a duplicate.
func epConfigForNetMode(
version string,
nwMode container.NetworkMode,
netConfig *network.NetworkingConfig,
) (*network.EndpointSettings, error) {
nwName := nwMode.NetworkName()
// It's always safe to create an EndpointsConfig entry under nwName if there are
// no entries already (because there can't be an entry for this network nwName
// refers to under any other name/short-id/id).
if len(netConfig.EndpointsConfig) == 0 {
es := &network.EndpointSettings{}
netConfig.EndpointsConfig = map[string]*network.EndpointSettings{
nwName: es,
}
return es, nil
}
// There cannot be more than one entry in EndpointsConfig with API < 1.44.
if versions.LessThan(version, "1.44") {
// No need to check for a match between NetworkMode and the names/ids in EndpointsConfig,
// the old version of the API would pick this network anyway.
for _, ep := range netConfig.EndpointsConfig {
return ep, nil
}
}
// There is existing endpoint config - if it's not indexed by NetworkMode.Name(), we
// can't tell which network the container-wide settings are intended for. NetworkMode,
// the keys in EndpointsConfig and the NetworkID in EndpointsConfig may mix network
// name/id/short-id. It's not safe to create EndpointsConfig under the NetworkMode
// name to store the container-wide setting, because that may result in two sets
// of EndpointsConfig for the same network and one set will be discarded later. So,
// reject the request ...
ep, ok := netConfig.EndpointsConfig[nwName]
if !ok {
return nil, errdefs.InvalidParameter(
errors.New("HostConfig.NetworkMode must match the identity of a network in NetworkSettings.Networks"))
}
return ep, nil
}
func (s *containerRouter) deleteContainers(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := httputils.ParseForm(r); err != nil {
return err
@@ -775,7 +925,7 @@ func (s *containerRouter) postContainersAttach(ctx context.Context, w http.Respo
}
contentType := types.MediaTypeRawStream
setupStreams := func(multiplexed bool) (io.ReadCloser, io.Writer, io.Writer, error) {
setupStreams := func(multiplexed bool, cancel func()) (io.ReadCloser, io.Writer, io.Writer, error) {
conn, _, err := hijacker.Hijack()
if err != nil {
return nil, nil, nil, err
@@ -793,6 +943,8 @@ func (s *containerRouter) postContainersAttach(ctx context.Context, w http.Respo
fmt.Fprintf(conn, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
}
go notifyClosed(ctx, conn, cancel)
closer := func() error {
httputils.CloseStreams(conn)
return nil
@@ -841,7 +993,7 @@ func (s *containerRouter) wsContainersAttach(ctx context.Context, w http.Respons
version := httputils.VersionFromContext(ctx)
setupStreams := func(multiplexed bool) (io.ReadCloser, io.Writer, io.Writer, error) {
setupStreams := func(multiplexed bool, cancel func()) (io.ReadCloser, io.Writer, io.Writer, error) {
wsChan := make(chan *websocket.Conn)
h := func(conn *websocket.Conn) {
wsChan <- conn
@@ -860,6 +1012,8 @@ func (s *containerRouter) wsContainersAttach(ctx context.Context, w http.Respons
if versions.GreaterThanOrEqualTo(version, "1.28") {
conn.PayloadType = websocket.BinaryFrame
}
// TODO: Close notifications
return conn, conn, conn, nil
}

View File

@@ -1,10 +1,12 @@
package container
import (
"strings"
"testing"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/libnetwork/netlabel"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@@ -102,7 +104,7 @@ func TestHandleMACAddressBC(t *testing.T) {
ctrWideMAC: "11:22:33:44:55:66",
networkMode: "aNetId",
epConfig: map[string]*network.EndpointSettings{"aNetName": {}},
expError: "if a container-wide MAC address is supplied, HostConfig.NetworkMode must match the identity of a network in NetworkSettings.Networks",
expError: "unable to migrate container-wide MAC address to a specific network: HostConfig.NetworkMode must match the identity of a network in NetworkSettings.Networks",
expCtrWideMAC: "11:22:33:44:55:66",
},
{
@@ -126,8 +128,8 @@ func TestHandleMACAddressBC(t *testing.T) {
}
epConfig := make(map[string]*network.EndpointSettings, len(tc.epConfig))
for k, v := range tc.epConfig {
v := v
epConfig[k] = v
v := *v
epConfig[k] = &v
}
netCfg := &network.NetworkingConfig{
EndpointsConfig: epConfig,
@@ -158,3 +160,191 @@ func TestHandleMACAddressBC(t *testing.T) {
})
}
}
func TestEpConfigForNetMode(t *testing.T) {
testcases := []struct {
name string
apiVersion string
networkMode string
epConfig map[string]*network.EndpointSettings
expEpId string
expNumEps int
expError bool
}{
{
name: "old api no eps",
apiVersion: "1.43",
networkMode: "mynet",
expNumEps: 1,
},
{
name: "new api no eps",
apiVersion: "1.44",
networkMode: "mynet",
expNumEps: 1,
},
{
name: "old api with ep",
apiVersion: "1.43",
networkMode: "mynet",
epConfig: map[string]*network.EndpointSettings{
"anything": {EndpointID: "epone"},
},
expEpId: "epone",
expNumEps: 1,
},
{
name: "new api with matching ep",
apiVersion: "1.44",
networkMode: "mynet",
epConfig: map[string]*network.EndpointSettings{
"mynet": {EndpointID: "epone"},
},
expEpId: "epone",
expNumEps: 1,
},
{
name: "new api with mismatched ep",
apiVersion: "1.44",
networkMode: "mynet",
epConfig: map[string]*network.EndpointSettings{
"shortid": {EndpointID: "epone"},
},
expError: true,
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
netConfig := &network.NetworkingConfig{
EndpointsConfig: tc.epConfig,
}
ep, err := epConfigForNetMode(tc.apiVersion, container.NetworkMode(tc.networkMode), netConfig)
if tc.expError {
assert.Check(t, is.ErrorContains(err, "HostConfig.NetworkMode must match the identity of a network in NetworkSettings.Networks"))
} else {
assert.Assert(t, err)
assert.Check(t, is.Equal(ep.EndpointID, tc.expEpId))
assert.Check(t, is.Len(netConfig.EndpointsConfig, tc.expNumEps))
}
})
}
}
func TestHandleSysctlBC(t *testing.T) {
testcases := []struct {
name string
apiVersion string
networkMode string
sysctls map[string]string
epConfig map[string]*network.EndpointSettings
expEpSysctls []string
expSysctls map[string]string
expWarningContains []string
expError string
}{
{
name: "migrate to new ep",
apiVersion: "1.46",
networkMode: "mynet",
sysctls: map[string]string{
"net.ipv6.conf.all.disable_ipv6": "0",
"net.ipv6.conf.eth0.accept_ra": "2",
"net.ipv6.conf.eth0.forwarding": "1",
},
expSysctls: map[string]string{
"net.ipv6.conf.all.disable_ipv6": "0",
},
expEpSysctls: []string{"net.ipv6.conf.IFNAME.forwarding=1", "net.ipv6.conf.IFNAME.accept_ra=2"},
expWarningContains: []string{
"Migrated",
"net.ipv6.conf.eth0.accept_ra", "net.ipv6.conf.IFNAME.accept_ra=2",
"net.ipv6.conf.eth0.forwarding", "net.ipv6.conf.IFNAME.forwarding=1",
},
},
{
name: "migrate nothing",
apiVersion: "1.46",
networkMode: "mynet",
sysctls: map[string]string{
"net.ipv6.conf.all.disable_ipv6": "0",
},
expSysctls: map[string]string{
"net.ipv6.conf.all.disable_ipv6": "0",
},
},
{
name: "migration disabled for newer api",
apiVersion: "1.47",
networkMode: "mynet",
sysctls: map[string]string{
"net.ipv6.conf.eth0.accept_ra": "2",
},
expError: "must be supplied using driver option 'com.docker.network.endpoint.sysctls'",
},
{
name: "only migrate eth0",
apiVersion: "1.46",
networkMode: "mynet",
sysctls: map[string]string{
"net.ipv6.conf.eth1.accept_ra": "2",
},
expError: "unable to determine network endpoint",
},
{
name: "net name mismatch",
apiVersion: "1.46",
networkMode: "mynet",
epConfig: map[string]*network.EndpointSettings{
"shortid": {EndpointID: "epone"},
},
sysctls: map[string]string{
"net.ipv6.conf.eth1.accept_ra": "2",
},
expError: "unable to find a network for sysctl",
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
hostCfg := &container.HostConfig{
NetworkMode: container.NetworkMode(tc.networkMode),
Sysctls: map[string]string{},
}
for k, v := range tc.sysctls {
hostCfg.Sysctls[k] = v
}
netCfg := &network.NetworkingConfig{
EndpointsConfig: tc.epConfig,
}
warnings, err := handleSysctlBC(hostCfg, netCfg, tc.apiVersion)
for _, s := range tc.expWarningContains {
assert.Check(t, is.Contains(warnings, s))
}
if tc.expError != "" {
assert.Check(t, is.ErrorContains(err, tc.expError))
} else {
assert.Check(t, err)
assert.Check(t, is.DeepEqual(hostCfg.Sysctls, tc.expSysctls))
ep := netCfg.EndpointsConfig[tc.networkMode]
if ep == nil {
assert.Check(t, is.Nil(tc.expEpSysctls))
} else {
got, ok := ep.DriverOpts[netlabel.EndpointSysctls]
assert.Check(t, ok)
// Check for expected ep-sysctls.
for _, want := range tc.expEpSysctls {
assert.Check(t, is.Contains(got, want))
}
// Check for unexpected ep-sysctls.
assert.Check(t, is.Len(got, len(strings.Join(tc.expEpSysctls, ","))))
}
}
})
}
}

View File

@@ -10,12 +10,12 @@ import (
"net/http"
"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
gddohttputil "github.com/golang/gddo/httputil"
)
// setContainerPathStatHeader encodes the stat to JSON, base64 encode, and place in a header.
func setContainerPathStatHeader(stat *types.ContainerPathStat, header http.Header) error {
func setContainerPathStatHeader(stat *container.PathStat, header http.Header) error {
statJSON, err := json.Marshal(stat)
if err != nil {
return err

View File

@@ -10,6 +10,7 @@ import (
"github.com/containerd/log"
"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/errdefs"
@@ -38,7 +39,7 @@ func (s *containerRouter) postContainerExecCreate(ctx context.Context, w http.Re
return err
}
execConfig := &types.ExecConfig{}
execConfig := &container.ExecOptions{}
if err := httputils.ReadJSON(r, execConfig); err != nil {
return err
}
@@ -77,8 +78,8 @@ func (s *containerRouter) postContainerExecStart(ctx context.Context, w http.Res
stdout, stderr, outStream io.Writer
)
execStartCheck := &types.ExecStartCheck{}
if err := httputils.ReadJSON(r, execStartCheck); err != nil {
options := &container.ExecStartOptions{}
if err := httputils.ReadJSON(r, options); err != nil {
return err
}
@@ -86,21 +87,21 @@ func (s *containerRouter) postContainerExecStart(ctx context.Context, w http.Res
return err
}
if execStartCheck.ConsoleSize != nil {
if options.ConsoleSize != nil {
version := httputils.VersionFromContext(ctx)
// Not supported before 1.42
if versions.LessThan(version, "1.42") {
execStartCheck.ConsoleSize = nil
options.ConsoleSize = nil
}
// No console without tty
if !execStartCheck.Tty {
execStartCheck.ConsoleSize = nil
if !options.Tty {
options.ConsoleSize = nil
}
}
if !execStartCheck.Detach {
if !options.Detach {
var err error
// Setting up the streaming http interface.
inStream, outStream, err = httputils.HijackConnection(w)
@@ -111,42 +112,43 @@ func (s *containerRouter) postContainerExecStart(ctx context.Context, w http.Res
if _, ok := r.Header["Upgrade"]; ok {
contentType := types.MediaTypeRawStream
if !execStartCheck.Tty && versions.GreaterThanOrEqualTo(httputils.VersionFromContext(ctx), "1.42") {
if !options.Tty && versions.GreaterThanOrEqualTo(httputils.VersionFromContext(ctx), "1.42") {
contentType = types.MediaTypeMultiplexedStream
}
fmt.Fprint(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: "+contentType+"\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n")
_, _ = fmt.Fprint(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: "+contentType+"\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n")
} else {
fmt.Fprint(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n")
_, _ = fmt.Fprint(outStream, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n")
}
// copy headers that were removed as part of hijack
if err := w.Header().WriteSubset(outStream, nil); err != nil {
return err
}
fmt.Fprint(outStream, "\r\n")
_, _ = fmt.Fprint(outStream, "\r\n")
stdin = inStream
stdout = outStream
if !execStartCheck.Tty {
if options.Tty {
stdout = outStream
} else {
stderr = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
stdout = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
}
}
options := container.ExecStartOptions{
// Now run the user process in container.
//
// TODO: Maybe we should we pass ctx here if we're not detaching?
err := s.backend.ContainerExecStart(context.Background(), execName, backend.ExecStartConfig{
Stdin: stdin,
Stdout: stdout,
Stderr: stderr,
ConsoleSize: execStartCheck.ConsoleSize,
}
// Now run the user process in container.
// Maybe we should we pass ctx here if we're not detaching?
if err := s.backend.ContainerExecStart(context.Background(), execName, options); err != nil {
if execStartCheck.Detach {
ConsoleSize: options.ConsoleSize,
})
if err != nil {
if options.Detach {
return err
}
stdout.Write([]byte(err.Error() + "\r\n"))
_, _ = fmt.Fprintf(stdout, "%v\r\n", err)
log.G(ctx).Errorf("Error running exec %s in container: %v", execName, err)
}
return nil

View File

@@ -0,0 +1,54 @@
package container
import (
"context"
"net"
"syscall"
"github.com/containerd/log"
"github.com/docker/docker/internal/unix_noeintr"
"golang.org/x/sys/unix"
)
func notifyClosed(ctx context.Context, conn net.Conn, notify func()) {
sc, ok := conn.(syscall.Conn)
if !ok {
log.G(ctx).Debug("notifyClosed: conn does not support close notifications")
return
}
rc, err := sc.SyscallConn()
if err != nil {
log.G(ctx).WithError(err).Warn("notifyClosed: failed get raw conn for close notifications")
return
}
epFd, err := unix_noeintr.EpollCreate()
if err != nil {
log.G(ctx).WithError(err).Warn("notifyClosed: failed to create epoll fd")
return
}
defer unix.Close(epFd)
err = rc.Control(func(fd uintptr) {
err := unix_noeintr.EpollCtl(epFd, unix.EPOLL_CTL_ADD, int(fd), &unix.EpollEvent{
Events: unix.EPOLLHUP,
Fd: int32(fd),
})
if err != nil {
log.G(ctx).WithError(err).Warn("notifyClosed: failed to register fd for close notifications")
return
}
events := make([]unix.EpollEvent, 1)
if _, err := unix_noeintr.EpollWait(epFd, events, -1); err != nil {
log.G(ctx).WithError(err).Warn("notifyClosed: failed to wait for close notifications")
return
}
notify()
})
if err != nil {
log.G(ctx).WithError(err).Warn("notifyClosed: failed to register for close notifications")
return
}
}

View File

@@ -0,0 +1,10 @@
//go:build !linux
package container
import (
"context"
"net"
)
func notifyClosed(ctx context.Context, conn net.Conn, notify func()) {}

View File

@@ -1,13 +1,21 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.21
package grpc // import "github.com/docker/docker/api/server/router/grpc"
import (
"context"
"fmt"
"os"
"strings"
"github.com/containerd/log"
"github.com/docker/docker/api/server/router"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/moby/buildkit/util/grpcerrors"
"github.com/moby/buildkit/util/stack"
"github.com/moby/buildkit/util/tracing"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
"golang.org/x/net/http2"
"google.golang.org/grpc"
)
@@ -20,12 +28,15 @@ type grpcRouter struct {
// NewRouter initializes a new grpc http router
func NewRouter(backends ...Backend) router.Router {
unary := grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(unaryInterceptor(), grpcerrors.UnaryServerInterceptor))
stream := grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(otelgrpc.StreamServerInterceptor(), grpcerrors.StreamServerInterceptor)) //nolint:staticcheck // TODO(thaJeztah): ignore SA1019 for deprecated options: see https://github.com/moby/moby/issues/47437
opts := []grpc.ServerOption{
grpc.StatsHandler(tracing.ServerStatsHandler(otelgrpc.WithTracerProvider(otel.GetTracerProvider()))),
grpc.ChainUnaryInterceptor(unaryInterceptor, grpcerrors.UnaryServerInterceptor),
grpc.StreamInterceptor(grpcerrors.StreamServerInterceptor),
}
r := &grpcRouter{
h2Server: &http2.Server{},
grpcServer: grpc.NewServer(unary, stream),
grpcServer: grpc.NewServer(opts...),
}
for _, b := range backends {
b.RegisterGRPC(r.grpcServer)
@@ -45,16 +56,20 @@ func (gr *grpcRouter) initRoutes() {
}
}
func unaryInterceptor() grpc.UnaryServerInterceptor {
withTrace := otelgrpc.UnaryServerInterceptor() //nolint:staticcheck // TODO(thaJeztah): ignore SA1019 for deprecated options: see https://github.com/moby/moby/issues/47437
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
// This method is used by the clients to send their traces to buildkit so they can be included
// in the daemon trace and stored in the build history record. This method can not be traced because
// it would cause an infinite loop.
if strings.HasSuffix(info.FullMethod, "opentelemetry.proto.collector.trace.v1.TraceService/Export") {
return handler(ctx, req)
}
return withTrace(ctx, req, info, handler)
func unaryInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
// This method is used by the clients to send their traces to buildkit so they can be included
// in the daemon trace and stored in the build history record. This method can not be traced because
// it would cause an infinite loop.
if strings.HasSuffix(info.FullMethod, "opentelemetry.proto.collector.trace.v1.TraceService/Export") {
return handler(ctx, req)
}
resp, err = handler(ctx, req)
if err != nil {
log.G(ctx).WithError(err).Error(info.FullMethod)
if log.GetLevel() >= log.DebugLevel {
fmt.Fprintf(os.Stderr, "%+v", stack.Formatter(grpcerrors.FromGRPC(err)))
}
}
return resp, err
}

View File

@@ -5,7 +5,6 @@ import (
"io"
"github.com/distribution/reference"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
@@ -28,7 +27,7 @@ type imageBackend interface {
Images(ctx context.Context, opts image.ListOptions) ([]*image.Summary, error)
GetImage(ctx context.Context, refOrID string, options backend.GetImageOpts) (*dockerimage.Image, error)
TagImage(ctx context.Context, id dockerimage.ID, newRef reference.Named) error
ImagesPrune(ctx context.Context, pruneFilters filters.Args) (*types.ImagesPruneReport, error)
ImagesPrune(ctx context.Context, pruneFilters filters.Args) (*image.PruneReport, error)
}
type importExportBackend interface {
@@ -39,7 +38,7 @@ type importExportBackend interface {
type registryBackend interface {
PullImage(ctx context.Context, ref reference.Named, platform *ocispec.Platform, metaHeaders map[string][]string, authConfig *registry.AuthConfig, outStream io.Writer) error
PushImage(ctx context.Context, ref reference.Named, metaHeaders map[string][]string, authConfig *registry.AuthConfig, outStream io.Writer) error
PushImage(ctx context.Context, ref reference.Named, platform *ocispec.Platform, metaHeaders map[string][]string, authConfig *registry.AuthConfig, outStream io.Writer) error
}
type Searcher interface {

View File

@@ -56,7 +56,7 @@ func (ir *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrit
if p := r.FormValue("platform"); p != "" {
sp, err := platforms.Parse(p)
if err != nil {
return err
return errdefs.InvalidParameter(err)
}
platform = &sp
}
@@ -205,7 +205,25 @@ func (ir *imageRouter) postImagesPush(ctx context.Context, w http.ResponseWriter
ref = r
}
if err := ir.backend.PushImage(ctx, ref, metaHeaders, authConfig, output); err != nil {
var platform *ocispec.Platform
// Platform is optional, and only supported in API version 1.46 and later.
// However the PushOptions struct previously was an alias for the PullOptions struct
// which also contained a Platform field.
// This means that older clients may be sending a platform field, even
// though it wasn't really supported by the server.
// Don't break these clients and just ignore the platform field on older APIs.
if versions.GreaterThanOrEqualTo(httputils.VersionFromContext(ctx), "1.46") {
if formPlatform := r.Form.Get("platform"); formPlatform != "" {
p, err := httputils.DecodePlatform(formPlatform)
if err != nil {
return err
}
platform = p
}
}
if err := ir.backend.PushImage(ctx, ref, platform, metaHeaders, authConfig, output); err != nil {
if !output.Flushed() {
return err
}

View File

@@ -3,7 +3,6 @@ package network // import "github.com/docker/docker/api/server/router/network"
import (
"context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/network"
@@ -12,20 +11,20 @@ import (
// Backend is all the methods that need to be implemented
// to provide network specific functionality.
type Backend interface {
GetNetworks(filters.Args, backend.NetworkListConfig) ([]types.NetworkResource, error)
CreateNetwork(nc types.NetworkCreateRequest) (*types.NetworkCreateResponse, error)
ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error
GetNetworks(filters.Args, backend.NetworkListConfig) ([]network.Inspect, error)
CreateNetwork(nc network.CreateRequest) (*network.CreateResponse, error)
ConnectContainerToNetwork(ctx context.Context, containerName, networkName string, endpointConfig *network.EndpointSettings) error
DisconnectContainerFromNetwork(containerName string, networkName string, force bool) error
DeleteNetwork(networkID string) error
NetworksPrune(ctx context.Context, pruneFilters filters.Args) (*types.NetworksPruneReport, error)
NetworksPrune(ctx context.Context, pruneFilters filters.Args) (*network.PruneReport, error)
}
// ClusterBackend is all the methods that need to be implemented
// to provide cluster network specific functionality.
type ClusterBackend interface {
GetNetworks(filters.Args) ([]types.NetworkResource, error)
GetNetwork(name string) (types.NetworkResource, error)
GetNetworksByName(name string) ([]types.NetworkResource, error)
CreateNetwork(nc types.NetworkCreateRequest) (string, error)
GetNetworks(filters.Args) ([]network.Inspect, error)
GetNetwork(name string) (network.Inspect, error)
GetNetworksByName(name string) ([]network.Inspect, error)
CreateNetwork(nc network.CreateRequest) (string, error)
RemoveNetwork(name string) error
}

View File

@@ -7,7 +7,6 @@ import (
"strings"
"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/network"
@@ -32,7 +31,7 @@ func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWrit
return err
}
var list []types.NetworkResource
var list []network.Summary
nr, err := n.cluster.GetNetworks(filter)
if err == nil {
list = nr
@@ -60,7 +59,7 @@ func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWrit
}
if list == nil {
list = []types.NetworkResource{}
list = []network.Summary{}
}
return httputils.WriteJSON(w, http.StatusOK, list)
@@ -109,8 +108,8 @@ func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r
// For full name and partial ID, save the result first, and process later
// in case multiple records was found based on the same term
listByFullName := map[string]types.NetworkResource{}
listByPartialID := map[string]types.NetworkResource{}
listByFullName := map[string]network.Inspect{}
listByPartialID := map[string]network.Inspect{}
// TODO(@cpuguy83): All this logic for figuring out which network to return does not belong here
// Instead there should be a backend function to just get one network.
@@ -204,7 +203,7 @@ func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWr
return err
}
var create types.NetworkCreateRequest
var create network.CreateRequest
if err := httputils.ReadJSON(r, &create); err != nil {
return err
}
@@ -226,7 +225,7 @@ func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWr
if err != nil {
return err
}
nw = &types.NetworkCreateResponse{
nw = &network.CreateResponse{
ID: id,
}
}
@@ -239,7 +238,7 @@ func (n *networkRouter) postNetworkConnect(ctx context.Context, w http.ResponseW
return err
}
var connect types.NetworkConnect
var connect network.ConnectOptions
if err := httputils.ReadJSON(r, &connect); err != nil {
return err
}
@@ -248,7 +247,7 @@ func (n *networkRouter) postNetworkConnect(ctx context.Context, w http.ResponseW
// The reason is that, In case of attachable network in swarm scope, the actual local network
// may not be available at the time. At the same time, inside daemon `ConnectContainerToNetwork`
// does the ambiguity check anyway. Therefore, passing the name to daemon would be enough.
return n.backend.ConnectContainerToNetwork(connect.Container, vars["id"], connect.EndpointConfig)
return n.backend.ConnectContainerToNetwork(ctx, connect.Container, vars["id"], connect.EndpointConfig)
}
func (n *networkRouter) postNetworkDisconnect(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
@@ -256,7 +255,7 @@ func (n *networkRouter) postNetworkDisconnect(ctx context.Context, w http.Respon
return err
}
var disconnect types.NetworkDisconnect
var disconnect network.DisconnectOptions
if err := httputils.ReadJSON(r, &disconnect); err != nil {
return err
}
@@ -311,9 +310,9 @@ func (n *networkRouter) postNetworksPrune(ctx context.Context, w http.ResponseWr
// For full name and partial ID, save the result first, and process later
// in case multiple records was found based on the same term
// TODO (yongtang): should we wrap with version here for backward compatibility?
func (n *networkRouter) findUniqueNetwork(term string) (types.NetworkResource, error) {
listByFullName := map[string]types.NetworkResource{}
listByPartialID := map[string]types.NetworkResource{}
func (n *networkRouter) findUniqueNetwork(term string) (network.Inspect, error) {
listByFullName := map[string]network.Inspect{}
listByPartialID := map[string]network.Inspect{}
filter := filters.NewArgs(filters.Arg("idOrName", term))
networks, _ := n.backend.GetNetworks(filter, backend.NetworkListConfig{Detailed: true})
@@ -363,7 +362,7 @@ func (n *networkRouter) findUniqueNetwork(term string) (types.NetworkResource, e
}
}
if len(listByFullName) > 1 {
return types.NetworkResource{}, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found based on name)", term, len(listByFullName)))
return network.Inspect{}, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found based on name)", term, len(listByFullName)))
}
// Find based on partial ID, returns true only if no duplicates
@@ -373,8 +372,8 @@ func (n *networkRouter) findUniqueNetwork(term string) (types.NetworkResource, e
}
}
if len(listByPartialID) > 1 {
return types.NetworkResource{}, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found based on ID prefix)", term, len(listByPartialID)))
return network.Inspect{}, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found based on ID prefix)", term, len(listByPartialID)))
}
return types.NetworkResource{}, errdefs.NotFound(libnetwork.ErrNoSuchNetwork(term))
return network.Inspect{}, errdefs.NotFound(libnetwork.ErrNoSuchNetwork(term))
}

View File

@@ -224,14 +224,6 @@ func (sr *swarmRouter) createService(ctx context.Context, w http.ResponseWriter,
adjustForAPIVersion(v, &service)
}
version := httputils.VersionFromContext(ctx)
if versions.LessThan(version, "1.44") {
if service.TaskTemplate.ContainerSpec != nil && service.TaskTemplate.ContainerSpec.Healthcheck != nil {
// StartInterval was added in API 1.44
service.TaskTemplate.ContainerSpec.Healthcheck.StartInterval = 0
}
}
resp, err := sr.backend.CreateService(service, encodedAuth, queryRegistry)
if err != nil {
log.G(ctx).WithFields(log.Fields{

View File

@@ -78,6 +78,16 @@ func adjustForAPIVersion(cliVersion string, service *swarm.ServiceSpec) {
if cliVersion == "" {
return
}
if versions.LessThan(cliVersion, "1.46") {
if service.TaskTemplate.ContainerSpec != nil {
for i, mount := range service.TaskTemplate.ContainerSpec.Mounts {
if mount.TmpfsOptions != nil {
mount.TmpfsOptions.Options = nil
service.TaskTemplate.ContainerSpec.Mounts[i] = mount
}
}
}
}
if versions.LessThan(cliVersion, "1.40") {
if service.TaskTemplate.ContainerSpec != nil {
// Sysctls for docker swarm services weren't supported before
@@ -121,11 +131,25 @@ func adjustForAPIVersion(cliVersion string, service *swarm.ServiceSpec) {
}
if versions.LessThan(cliVersion, "1.44") {
// seccomp, apparmor, and no_new_privs were added in 1.44.
if service.TaskTemplate.ContainerSpec != nil && service.TaskTemplate.ContainerSpec.Privileges != nil {
service.TaskTemplate.ContainerSpec.Privileges.Seccomp = nil
service.TaskTemplate.ContainerSpec.Privileges.AppArmor = nil
service.TaskTemplate.ContainerSpec.Privileges.NoNewPrivileges = false
if service.TaskTemplate.ContainerSpec != nil {
// seccomp, apparmor, and no_new_privs were added in 1.44.
if service.TaskTemplate.ContainerSpec.Privileges != nil {
service.TaskTemplate.ContainerSpec.Privileges.Seccomp = nil
service.TaskTemplate.ContainerSpec.Privileges.AppArmor = nil
service.TaskTemplate.ContainerSpec.Privileges.NoNewPrivileges = false
}
if service.TaskTemplate.ContainerSpec.Healthcheck != nil {
// StartInterval was added in API 1.44
service.TaskTemplate.ContainerSpec.Healthcheck.StartInterval = 0
}
}
}
if versions.LessThan(cliVersion, "1.46") {
if service.TaskTemplate.ContainerSpec != nil && service.TaskTemplate.ContainerSpec.OomScoreAdj != 0 {
// OomScoreAdj was added in API 1.46
service.TaskTemplate.ContainerSpec.OomScoreAdj = 0
}
}
}

View File

@@ -4,8 +4,9 @@ import (
"reflect"
"testing"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/go-units"
)
func TestAdjustForAPIVersion(t *testing.T) {
@@ -38,13 +39,25 @@ func TestAdjustForAPIVersion(t *testing.T) {
ConfigName: "configRuntime",
},
},
Ulimits: []*units.Ulimit{
Ulimits: []*container.Ulimit{
{
Name: "nofile",
Soft: 100,
Hard: 200,
},
},
Mounts: []mount.Mount{
{
Type: mount.TypeTmpfs,
Source: "/foo",
Target: "/bar",
TmpfsOptions: &mount.TmpfsOptions{
Options: [][]string{
[]string{"exec"},
},
},
},
},
},
Placement: &swarm.Placement{
MaxReplicas: 222,
@@ -57,6 +70,19 @@ func TestAdjustForAPIVersion(t *testing.T) {
},
}
adjustForAPIVersion("1.46", spec)
if !reflect.DeepEqual(
spec.TaskTemplate.ContainerSpec.Mounts[0].TmpfsOptions.Options,
[][]string{[]string{"exec"}},
) {
t.Error("TmpfsOptions.Options was stripped from spec")
}
adjustForAPIVersion("1.45", spec)
if len(spec.TaskTemplate.ContainerSpec.Mounts[0].TmpfsOptions.Options) != 0 {
t.Error("TmpfsOptions.Options not stripped from spec")
}
// first, does calling this with a later version correctly NOT strip
// fields? do the later version first, so we can reuse this spec in the
// next test.

View File

@@ -1,5 +1,5 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.19
//go:build go1.21
package system // import "github.com/docker/docker/api/server/router/system"

View File

@@ -97,6 +97,10 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
info.Runtimes[k] = system.RuntimeWithStatus{Runtime: rt.Runtime}
}
}
if versions.LessThan(version, "1.46") {
// Containerd field introduced in API v1.46.
info.Containerd = nil
}
if versions.GreaterThanOrEqualTo(version, "1.42") {
info.KernelMemory = false
}
@@ -263,6 +267,7 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
output := ioutils.NewWriteFlusher(w)
defer output.Close()
output.Flush()
@@ -272,7 +277,18 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
buffered, l := s.backend.SubscribeToEvents(since, until, ef)
defer s.backend.UnsubscribeFromEvents(l)
shouldSkip := func(ev events.Message) bool { return false }
if versions.LessThan(httputils.VersionFromContext(ctx), "1.46") {
// Image create events were added in API 1.46
shouldSkip = func(ev events.Message) bool {
return ev.Type == "image" && ev.Action == "create"
}
}
for _, ev := range buffered {
if shouldSkip(ev) {
continue
}
if err := enc.Encode(ev); err != nil {
return err
}
@@ -290,6 +306,9 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
log.G(ctx).Warnf("unexpected event message: %q", ev)
continue
}
if shouldSkip(jev) {
continue
}
if err := enc.Encode(jev); err != nil {
return err
}

View File

@@ -3,11 +3,9 @@ package volume // import "github.com/docker/docker/api/server/router/volume"
import (
"context"
"github.com/docker/docker/volume/service/opts"
// TODO return types need to be refactored into pkg
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/volume/service/opts"
)
// Backend is the methods that need to be implemented to provide
@@ -17,7 +15,7 @@ type Backend interface {
Get(ctx context.Context, name string, opts ...opts.GetOption) (*volume.Volume, error)
Create(ctx context.Context, name, driverName string, opts ...opts.CreateOption) (*volume.Volume, error)
Remove(ctx context.Context, name string, opts ...opts.RemoveOption) error
Prune(ctx context.Context, pruneFilters filters.Args) (*types.VolumesPruneReport, error)
Prune(ctx context.Context, pruneFilters filters.Args) (*volume.PruneReport, error)
}
// ClusterBackend is the backend used for Swarm Cluster Volumes. Regular

View File

@@ -11,7 +11,6 @@ import (
"gotest.tools/v3/assert"
"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/errdefs"
@@ -636,7 +635,7 @@ func (b *fakeVolumeBackend) Remove(_ context.Context, name string, o ...opts.Rem
return nil
}
func (b *fakeVolumeBackend) Prune(_ context.Context, _ filters.Args) (*types.VolumesPruneReport, error) {
func (b *fakeVolumeBackend) Prune(_ context.Context, _ filters.Args) (*volume.PruneReport, error) {
return nil, nil
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
package auxprogress
import (
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// ManifestPushedInsteadOfIndex is a note that is sent when a manifest is pushed
// instead of an index. It is sent when the pushed image is an multi-platform
// index, but the whole index couldn't be pushed.
type ManifestPushedInsteadOfIndex struct {
ManifestPushedInsteadOfIndex bool `json:"manifestPushedInsteadOfIndex"` // Always true
// OriginalIndex is the descriptor of the original image index.
OriginalIndex ocispec.Descriptor `json:"originalIndex"`
// SelectedManifest is the descriptor of the manifest that was pushed instead.
SelectedManifest ocispec.Descriptor `json:"selectedManifest"`
}
// ContentMissing is a note that is sent when push fails because the content is missing.
type ContentMissing struct {
ContentMissing bool `json:"contentMissing"` // Always true
// Desc is the descriptor of the root object that was attempted to be pushed.
Desc ocispec.Descriptor `json:"desc"`
}

View File

@@ -30,7 +30,7 @@ type ContainerRmConfig struct {
// ContainerAttachConfig holds the streams to use when connecting to a container to view logs.
type ContainerAttachConfig struct {
GetStreams func(multiplexed bool) (io.ReadCloser, io.Writer, io.Writer, error)
GetStreams func(multiplexed bool, cancel func()) (io.ReadCloser, io.Writer, io.Writer, error)
UseStdin bool
UseStdout bool
UseStderr bool
@@ -89,7 +89,15 @@ type LogSelector struct {
type ContainerStatsConfig struct {
Stream bool
OneShot bool
OutStream io.Writer
OutStream func() io.Writer
}
// ExecStartConfig holds the options to start container's exec.
type ExecStartConfig struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
ConsoleSize *[2]uint `json:",omitempty"`
}
// ExecInspect holds information about a running process started

View File

@@ -2,43 +2,15 @@ package types // import "github.com/docker/docker/api/types"
import (
"bufio"
"context"
"io"
"net"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/registry"
units "github.com/docker/go-units"
)
// ContainerExecInspect holds information returned by exec inspect.
type ContainerExecInspect struct {
ExecID string `json:"ID"`
ContainerID string
Running bool
ExitCode int
Pid int
}
// CopyToContainerOptions holds information
// about files to copy into a container
type CopyToContainerOptions struct {
AllowOverwriteDirWithFile bool
CopyUIDGID bool
}
// EventsOptions holds parameters to filter events with.
type EventsOptions struct {
Since string
Until string
Filters filters.Args
}
// NetworkListOptions holds parameters to filter the list of networks with.
type NetworkListOptions struct {
Filters filters.Args
}
// NewHijackedResponse intializes a HijackedResponse type
func NewHijackedResponse(conn net.Conn, mediaType string) HijackedResponse {
return HijackedResponse{Conn: conn, Reader: bufio.NewReader(conn), mediaType: mediaType}
@@ -101,7 +73,7 @@ type ImageBuildOptions struct {
NetworkMode string
ShmSize int64
Dockerfile string
Ulimits []*units.Ulimit
Ulimits []*container.Ulimit
// BuildArgs needs to be a *string instead of just a string so that
// we can tell the difference between "" (empty string) and no value
// at all (nil). See the parsing of buildArgs in
@@ -122,7 +94,7 @@ type ImageBuildOptions struct {
Target string
SessionID string
Platform string
// Version specifies the version of the unerlying builder to use
// Version specifies the version of the underlying builder to use
Version BuilderVersion
// BuildID is an optional identifier that can be passed together with the
// build request. The same identifier can be used to gracefully cancel the
@@ -157,34 +129,13 @@ type ImageBuildResponse struct {
OSType string
}
// ImageImportSource holds source information for ImageImport
type ImageImportSource struct {
Source io.Reader // Source is the data to send to the server to create this image from. You must set SourceName to "-" to leverage this.
SourceName string // SourceName is the name of the image to pull. Set to "-" to leverage the Source attribute.
}
// ImageLoadResponse returns information to the client about a load process.
type ImageLoadResponse struct {
// Body must be closed to avoid a resource leak
Body io.ReadCloser
JSON bool
}
// RequestPrivilegeFunc is a function interface that
// clients can supply to retry operations after
// getting an authorization error.
// This function returns the registry authentication
// header value in base 64 format, or an error
// if the privilege request fails.
type RequestPrivilegeFunc func() (string, error)
// ImageSearchOptions holds parameters to search images with.
type ImageSearchOptions struct {
RegistryAuth string
PrivilegeFunc RequestPrivilegeFunc
Filters filters.Args
Limit int
}
type RequestPrivilegeFunc func(context.Context) (string, error)
// NodeListOptions holds parameters to list nodes with.
type NodeListOptions struct {
@@ -289,7 +240,7 @@ type PluginInstallOptions struct {
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
RemoteRef string // RemoteRef is the plugin name on the registry
PrivilegeFunc RequestPrivilegeFunc
AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
AcceptPermissionsFunc func(context.Context, PluginPrivileges) (bool, error)
Args []string
}

View File

@@ -1,18 +0,0 @@
package types // import "github.com/docker/docker/api/types"
// ExecConfig is a small subset of the Config struct that holds the configuration
// for the exec feature of docker.
type ExecConfig struct {
User string // User that will run the command
Privileged bool // Is the container in privileged mode
Tty bool // Attach standard streams to a tty.
ConsoleSize *[2]uint `json:",omitempty"` // Initial console size [height, width]
AttachStdin bool // Attach the standard input, makes possible user interaction
AttachStderr bool // Attach the standard error
AttachStdout bool // Attach the standard output
Detach bool // Execute in detach mode
DetachKeys string // Escape keys for detach
Env []string // Environment variables
WorkingDir string // Working directory
Cmd []string // Execution commands and args
}

View File

@@ -1,7 +1,6 @@
package container // import "github.com/docker/docker/api/types/container"
import (
"io"
"time"
"github.com/docker/docker/api/types/strslice"
@@ -36,14 +35,6 @@ type StopOptions struct {
// HealthConfig holds configuration settings for the HEALTHCHECK feature.
type HealthConfig = dockerspec.HealthcheckConfig
// ExecStartOptions holds the options to start container's exec.
type ExecStartOptions struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
ConsoleSize *[2]uint `json:",omitempty"`
}
// Config contains the configuration data about a container.
// It should hold only portable information about the container.
// Here, "portable" means "independent from the host we are running on".

View File

@@ -0,0 +1,44 @@
package container
import (
"io"
"os"
"time"
)
// PruneReport contains the response for Engine API:
// POST "/containers/prune"
type PruneReport struct {
ContainersDeleted []string
SpaceReclaimed uint64
}
// PathStat is used to encode the header from
// GET "/containers/{name:.*}/archive"
// "Name" is the file or directory name.
type PathStat struct {
Name string `json:"name"`
Size int64 `json:"size"`
Mode os.FileMode `json:"mode"`
Mtime time.Time `json:"mtime"`
LinkTarget string `json:"linkTarget"`
}
// CopyToContainerOptions holds information
// about files to copy into a container
type CopyToContainerOptions struct {
AllowOverwriteDirWithFile bool
CopyUIDGID bool
}
// StatsResponseReader wraps an io.ReadCloser to read (a stream of) stats
// for a container, as produced by the GET "/stats" endpoint.
//
// The OSType field is set to the server's platform to allow
// platform-specific handling of the response.
//
// TODO(thaJeztah): remove this wrapper, and make OSType part of [StatsResponse].
type StatsResponseReader struct {
Body io.ReadCloser `json:"body"`
OSType string `json:"ostype"`
}

View File

@@ -0,0 +1,13 @@
package container
import "github.com/docker/docker/api/types/network"
// CreateRequest is the request message sent to the server for container
// create calls. It is a config wrapper that holds the container [Config]
// (portable) and the corresponding [HostConfig] (non-portable) and
// [network.NetworkingConfig].
type CreateRequest struct {
*Config
HostConfig *HostConfig `json:"HostConfig,omitempty"`
NetworkingConfig *network.NetworkingConfig `json:"NetworkingConfig,omitempty"`
}

View File

@@ -0,0 +1,43 @@
package container
// ExecOptions is a small subset of the Config struct that holds the configuration
// for the exec feature of docker.
type ExecOptions struct {
User string // User that will run the command
Privileged bool // Is the container in privileged mode
Tty bool // Attach standard streams to a tty.
ConsoleSize *[2]uint `json:",omitempty"` // Initial console size [height, width]
AttachStdin bool // Attach the standard input, makes possible user interaction
AttachStderr bool // Attach the standard error
AttachStdout bool // Attach the standard output
Detach bool // Execute in detach mode
DetachKeys string // Escape keys for detach
Env []string // Environment variables
WorkingDir string // Working directory
Cmd []string // Execution commands and args
}
// ExecStartOptions is a temp struct used by execStart
// Config fields is part of ExecConfig in runconfig package
type ExecStartOptions struct {
// ExecStart will first check if it's detached
Detach bool
// Check if there's a tty
Tty bool
// Terminal size [height, width], unused if Tty == false
ConsoleSize *[2]uint `json:",omitempty"`
}
// ExecAttachOptions is a temp struct used by execAttach.
//
// TODO(thaJeztah): make this a separate type; ContainerExecAttach does not use the Detach option, and cannot run detached.
type ExecAttachOptions = ExecStartOptions
// ExecInspect holds information returned by exec inspect.
type ExecInspect struct {
ExecID string `json:"ID"`
ContainerID string
Running bool
ExitCode int
Pid int
}

View File

@@ -360,6 +360,12 @@ type LogConfig struct {
Config map[string]string
}
// Ulimit is an alias for [units.Ulimit], which may be moving to a different
// location or become a local type. This alias is to help transitioning.
//
// Users are recommended to use this alias instead of using [units.Ulimit] directly.
type Ulimit = units.Ulimit
// Resources contains container's resources (cgroups config, ulimits...)
type Resources struct {
// Applicable to all platforms
@@ -387,14 +393,14 @@ type Resources struct {
// KernelMemory specifies the kernel memory limit (in bytes) for the container.
// Deprecated: kernel 5.4 deprecated kmem.limit_in_bytes.
KernelMemory int64 `json:",omitempty"`
KernelMemoryTCP int64 `json:",omitempty"` // Hard limit for kernel TCP buffer memory (in bytes)
MemoryReservation int64 // Memory soft limit (in bytes)
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
MemorySwappiness *int64 // Tuning container memory swappiness behaviour
OomKillDisable *bool // Whether to disable OOM Killer or not
PidsLimit *int64 // Setting PIDs limit for a container; Set `0` or `-1` for unlimited, or `null` to not change.
Ulimits []*units.Ulimit // List of ulimits to be set in the container
KernelMemory int64 `json:",omitempty"`
KernelMemoryTCP int64 `json:",omitempty"` // Hard limit for kernel TCP buffer memory (in bytes)
MemoryReservation int64 // Memory soft limit (in bytes)
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
MemorySwappiness *int64 // Tuning container memory swappiness behaviour
OomKillDisable *bool // Whether to disable OOM Killer or not
PidsLimit *int64 // Setting PIDs limit for a container; Set `0` or `-1` for unlimited, or `null` to not change.
Ulimits []*Ulimit // List of ulimits to be set in the container
// Applicable to Windows
CPUCount int64 `json:"CpuCount"` // CPU count

View File

@@ -9,24 +9,6 @@ func (i Isolation) IsValid() bool {
return i.IsDefault()
}
// NetworkName returns the name of the network stack.
func (n NetworkMode) NetworkName() string {
if n.IsBridge() {
return network.NetworkBridge
} else if n.IsHost() {
return network.NetworkHost
} else if n.IsContainer() {
return "container"
} else if n.IsNone() {
return network.NetworkNone
} else if n.IsDefault() {
return network.NetworkDefault
} else if n.IsUserDefined() {
return n.UserDefined()
}
return ""
}
// IsBridge indicates whether container uses the bridge network stack
func (n NetworkMode) IsBridge() bool {
return n == network.NetworkBridge
@@ -41,3 +23,23 @@ func (n NetworkMode) IsHost() bool {
func (n NetworkMode) IsUserDefined() bool {
return !n.IsDefault() && !n.IsBridge() && !n.IsHost() && !n.IsNone() && !n.IsContainer()
}
// NetworkName returns the name of the network stack.
func (n NetworkMode) NetworkName() string {
switch {
case n.IsDefault():
return network.NetworkDefault
case n.IsBridge():
return network.NetworkBridge
case n.IsHost():
return network.NetworkHost
case n.IsNone():
return network.NetworkNone
case n.IsContainer():
return "container"
case n.IsUserDefined():
return n.UserDefined()
default:
return ""
}
}

View File

@@ -2,6 +2,11 @@ package container // import "github.com/docker/docker/api/types/container"
import "github.com/docker/docker/api/types/network"
// IsValid indicates if an isolation technology is valid
func (i Isolation) IsValid() bool {
return i.IsDefault() || i.IsHyperV() || i.IsProcess()
}
// IsBridge indicates whether container uses the bridge network stack
// in windows it is given the name NAT
func (n NetworkMode) IsBridge() bool {
@@ -19,24 +24,24 @@ func (n NetworkMode) IsUserDefined() bool {
return !n.IsDefault() && !n.IsNone() && !n.IsBridge() && !n.IsContainer()
}
// IsValid indicates if an isolation technology is valid
func (i Isolation) IsValid() bool {
return i.IsDefault() || i.IsHyperV() || i.IsProcess()
}
// NetworkName returns the name of the network stack.
func (n NetworkMode) NetworkName() string {
if n.IsDefault() {
switch {
case n.IsDefault():
return network.NetworkDefault
} else if n.IsBridge() {
case n.IsBridge():
return network.NetworkNat
} else if n.IsNone() {
case n.IsHost():
// Windows currently doesn't support host network-mode, so
// this would currently never happen..
return network.NetworkHost
case n.IsNone():
return network.NetworkNone
} else if n.IsContainer() {
case n.IsContainer():
return "container"
} else if n.IsUserDefined() {
case n.IsUserDefined():
return n.UserDefined()
default:
return ""
}
return ""
}

View File

@@ -1,6 +1,4 @@
// Package types is used for API stability in the types and response to the
// consumers of the API stats endpoint.
package types // import "github.com/docker/docker/api/types"
package container
import "time"
@@ -169,8 +167,10 @@ type Stats struct {
MemoryStats MemoryStats `json:"memory_stats,omitempty"`
}
// StatsJSON is newly used Networks
type StatsJSON struct {
// StatsResponse is newly used Networks.
//
// TODO(thaJeztah): unify with [Stats]. This wrapper was to account for pre-api v1.21 changes, see https://github.com/moby/moby/commit/d3379946ec96fb6163cb8c4517d7d5a067045801
type StatsResponse struct {
Stats
Name string `json:"name,omitempty"`

View File

@@ -1,4 +1,5 @@
package events // import "github.com/docker/docker/api/types/events"
import "github.com/docker/docker/api/types/filters"
// Type is used for event-types.
type Type string
@@ -125,3 +126,10 @@ type Message struct {
Time int64 `json:"time,omitempty"`
TimeNano int64 `json:"timeNano,omitempty"`
}
// ListOptions holds parameters to filter events with.
type ListOptions struct {
Since string
Until string
Filters filters.Args
}

View File

@@ -1,9 +1,47 @@
package image
import "time"
import (
"io"
"time"
)
// Metadata contains engine-local data about the image.
type Metadata struct {
// LastTagTime is the date and time at which the image was last tagged.
LastTagTime time.Time `json:",omitempty"`
}
// PruneReport contains the response for Engine API:
// POST "/images/prune"
type PruneReport struct {
ImagesDeleted []DeleteResponse
SpaceReclaimed uint64
}
// LoadResponse returns information to the client about a load process.
//
// TODO(thaJeztah): remove this type, and just use an io.ReadCloser
//
// This type was added in https://github.com/moby/moby/pull/18878, related
// to https://github.com/moby/moby/issues/19177;
//
// Make docker load to output json when the response content type is json
// Swarm hijacks the response from docker load and returns JSON rather
// than plain text like the Engine does. This makes the API library to return
// information to figure that out.
//
// However the "load" endpoint unconditionally returns JSON;
// https://github.com/moby/moby/blob/7b9d2ef6e5518a3d3f3cc418459f8df786cfbbd1/api/server/router/image/image_routes.go#L248-L255
//
// PR https://github.com/moby/moby/pull/21959 made the response-type depend
// on whether "quiet" was set, but this logic got changed in a follow-up
// https://github.com/moby/moby/pull/25557, which made the JSON response-type
// unconditionally, but the output produced depend on whether"quiet" was set.
//
// We should deprecated the "quiet" option, as it's really a client
// responsibility.
type LoadResponse struct {
// Body must be closed to avoid a resource leak
Body io.ReadCloser
JSON bool
}

View File

@@ -1,6 +1,18 @@
package image
import "github.com/docker/docker/api/types/filters"
import (
"context"
"io"
"github.com/docker/docker/api/types/filters"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// ImportSource holds source information for ImageImport
type ImportSource struct {
Source io.Reader // Source is the data to send to the server to create this image from. You must set SourceName to "-" to leverage this.
SourceName string // SourceName is the name of the image to pull. Set to "-" to leverage the Source attribute.
}
// ImportOptions holds information to import images from the client host.
type ImportOptions struct {
@@ -27,12 +39,28 @@ type PullOptions struct {
// privilege request fails.
//
// Also see [github.com/docker/docker/api/types.RequestPrivilegeFunc].
PrivilegeFunc func() (string, error)
PrivilegeFunc func(context.Context) (string, error)
Platform string
}
// PushOptions holds information to push images.
type PushOptions PullOptions
type PushOptions struct {
All bool
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
// PrivilegeFunc is a function that clients can supply to retry operations
// after getting an authorization error. This function returns the registry
// authentication header value in base64 encoded format, or an error if the
// privilege request fails.
//
// Also see [github.com/docker/docker/api/types.RequestPrivilegeFunc].
PrivilegeFunc func(context.Context) (string, error)
// Platform is an optional field that selects a specific platform to push
// when the image is a multi-platform image.
// Using this will only push a single platform-specific manifest.
Platform *ocispec.Platform `json:",omitempty"`
}
// ListOptions holds parameters to list images with.
type ListOptions struct {

View File

@@ -119,7 +119,11 @@ type TmpfsOptions struct {
SizeBytes int64 `json:",omitempty"`
// Mode of the tmpfs upon creation
Mode os.FileMode `json:",omitempty"`
// Options to be passed to the tmpfs mount. An array of arrays. Flag
// options should be provided as 1-length arrays. Other types should be
// provided as 2-length arrays, where the first item is the key and the
// second the value.
Options [][]string `json:",omitempty"`
// TODO(stevvooe): There are several more tmpfs flags, specified in the
// daemon, that are accepted. Only the most basic are added for now.
//

View File

@@ -0,0 +1,19 @@
package network
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// CreateResponse NetworkCreateResponse
//
// OK response to NetworkCreate operation
// swagger:model CreateResponse
type CreateResponse struct {
// The ID of the created network.
// Required: true
ID string `json:"Id"`
// Warnings encountered when creating the container
// Required: true
Warning string `json:"Warning"`
}

View File

@@ -18,6 +18,7 @@ type EndpointSettings struct {
// Once the container is running, it becomes operational data (it may contain a
// generated address).
MacAddress string
DriverOpts map[string]string
// Operational data
NetworkID string
EndpointID string
@@ -27,7 +28,6 @@ type EndpointSettings struct {
IPv6Gateway string
GlobalIPv6Address string
GlobalIPv6PrefixLen int
DriverOpts map[string]string
// DNSNames holds all the (non fully qualified) DNS names associated to this endpoint. First entry is used to
// generate PTR records.
DNSNames []string

View File

@@ -1,6 +1,8 @@
package network // import "github.com/docker/docker/api/types/network"
import (
"time"
"github.com/docker/docker/api/types/filters"
)
@@ -17,6 +19,82 @@ const (
NetworkNat = "nat"
)
// CreateRequest is the request message sent to the server for network create call.
type CreateRequest struct {
CreateOptions
Name string // Name is the requested name of the network.
// Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client
// package to older daemons.
CheckDuplicate *bool `json:",omitempty"`
}
// CreateOptions holds options to create a network.
type CreateOptions struct {
Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`)
Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level).
EnableIPv6 *bool `json:",omitempty"` // EnableIPv6 represents whether to enable IPv6.
IPAM *IPAM // IPAM is the network's IP Address Management.
Internal bool // Internal represents if the network is used internal only.
Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
ConfigOnly bool // ConfigOnly creates a config-only network. Config-only networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services.
ConfigFrom *ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. The specified network must be a config-only network; see [CreateOptions.ConfigOnly].
Options map[string]string // Options specifies the network-specific options to use for when creating the network.
Labels map[string]string // Labels holds metadata specific to the network being created.
}
// ListOptions holds parameters to filter the list of networks with.
type ListOptions struct {
Filters filters.Args
}
// InspectOptions holds parameters to inspect network.
type InspectOptions struct {
Scope string
Verbose bool
}
// ConnectOptions represents the data to be used to connect a container to the
// network.
type ConnectOptions struct {
Container string
EndpointConfig *EndpointSettings `json:",omitempty"`
}
// DisconnectOptions represents the data to be used to disconnect a container
// from the network.
type DisconnectOptions struct {
Container string
Force bool
}
// Inspect is the body of the "get network" http response message.
type Inspect struct {
Name string // Name is the name of the network
ID string `json:"Id"` // ID uniquely identifies a network on a single machine
Created time.Time // Created is the time the network created
Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level)
Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
IPAM IPAM // IPAM is the network's IP Address Management
Internal bool // Internal represents if the network is used internal only
Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
ConfigFrom ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network.
ConfigOnly bool // ConfigOnly networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services.
Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
Options map[string]string // Options holds the network specific options to use for when creating the network
Labels map[string]string // Labels holds metadata specific to the network being created
Peers []PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network
Services map[string]ServiceInfo `json:",omitempty"`
}
// Summary is used as response when listing networks. It currently is an alias
// for [Inspect], but may diverge in the future, as not all information may
// be included when listing networks.
type Summary = Inspect
// Address represents an IP address
type Address struct {
Addr string
@@ -45,6 +123,16 @@ type ServiceInfo struct {
Tasks []Task
}
// EndpointResource contains network resources allocated and used for a
// container in a network.
type EndpointResource struct {
Name string
EndpointID string
MacAddress string
IPv4Address string
IPv6Address string
}
// NetworkingConfig represents the container's networking configuration for each of its interfaces
// Carries the networking configs specified in the `docker run` and `docker network connect` commands
type NetworkingConfig struct {
@@ -70,3 +158,9 @@ var acceptedFilters = map[string]bool{
func ValidateFilters(filter filters.Args) error {
return filter.Validate(acceptedFilters)
}
// PruneReport contains the response for Engine API:
// POST "/networks/prune"
type PruneReport struct {
NetworksDeleted []string
}

View File

@@ -84,32 +84,6 @@ type IndexInfo struct {
Official bool
}
// SearchResult describes a search result returned from a registry
type SearchResult struct {
// StarCount indicates the number of stars this repository has
StarCount int `json:"star_count"`
// IsOfficial is true if the result is from an official repository.
IsOfficial bool `json:"is_official"`
// Name is the name of the repository
Name string `json:"name"`
// IsAutomated indicates whether the result is automated.
//
// Deprecated: the "is_automated" field is deprecated and will always be "false".
IsAutomated bool `json:"is_automated"`
// Description is a textual description of the repository
Description string `json:"description"`
}
// SearchResults lists a collection search results returned from a registry
type SearchResults struct {
// Query contains the query string that generated the search results
Query string `json:"query"`
// NumResults indicates the number of results the query returned
NumResults int `json:"num_results"`
// Results is a slice containing the actual results for the search
Results []SearchResult `json:"results"`
}
// DistributionInspect describes the result obtained from contacting the
// registry to retrieve image metadata
type DistributionInspect struct {

View File

@@ -0,0 +1,47 @@
package registry
import (
"context"
"github.com/docker/docker/api/types/filters"
)
// SearchOptions holds parameters to search images with.
type SearchOptions struct {
RegistryAuth string
// PrivilegeFunc is a [types.RequestPrivilegeFunc] the client can
// supply to retry operations after getting an authorization error.
//
// It must return the registry authentication header value in base64
// format, or an error if the privilege request fails.
PrivilegeFunc func(context.Context) (string, error)
Filters filters.Args
Limit int
}
// SearchResult describes a search result returned from a registry
type SearchResult struct {
// StarCount indicates the number of stars this repository has
StarCount int `json:"star_count"`
// IsOfficial is true if the result is from an official repository.
IsOfficial bool `json:"is_official"`
// Name is the name of the repository
Name string `json:"name"`
// IsAutomated indicates whether the result is automated.
//
// Deprecated: the "is_automated" field is deprecated and will always be "false".
IsAutomated bool `json:"is_automated"`
// Description is a textual description of the repository
Description string `json:"description"`
}
// SearchResults lists a collection search results returned from a registry
type SearchResults struct {
// Query contains the query string that generated the search results
Query string `json:"query"`
// NumResults indicates the number of results the query returned
NumResults int `json:"num_results"`
// Results is a slice containing the actual results for the search
Results []SearchResult `json:"results"`
}

View File

@@ -5,7 +5,6 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
"github.com/docker/go-units"
)
// DNSConfig specifies DNS related configurations in resolver configuration file (resolv.conf)
@@ -115,5 +114,6 @@ type ContainerSpec struct {
Sysctls map[string]string `json:",omitempty"`
CapabilityAdd []string `json:",omitempty"`
CapabilityDrop []string `json:",omitempty"`
Ulimits []*units.Ulimit `json:",omitempty"`
Ulimits []*container.Ulimit `json:",omitempty"`
OomScoreAdj int64 `json:",omitempty"`
}

View File

@@ -75,6 +75,8 @@ type Info struct {
DefaultAddressPools []NetworkAddressPool `json:",omitempty"`
CDISpecDirs []string
Containerd *ContainerdInfo `json:",omitempty"`
// Legacy API fields for older API versions.
legacyFields
@@ -85,6 +87,43 @@ type Info struct {
Warnings []string
}
// ContainerdInfo holds information about the containerd instance used by the daemon.
type ContainerdInfo struct {
// Address is the path to the containerd socket.
Address string `json:",omitempty"`
// Namespaces is the containerd namespaces used by the daemon.
Namespaces ContainerdNamespaces
}
// ContainerdNamespaces reflects the containerd namespaces used by the daemon.
//
// These namespaces can be configured in the daemon configuration, and are
// considered to be used exclusively by the daemon,
//
// As these namespaces are considered to be exclusively accessed
// by the daemon, it is not recommended to change these values,
// or to change them to a value that is used by other systems,
// such as cri-containerd.
type ContainerdNamespaces struct {
// Containers holds the default containerd namespace used for
// containers managed by the daemon.
//
// The default namespace for containers is "moby", but will be
// suffixed with the `<uid>.<gid>` of the remapped `root` if
// user-namespaces are enabled and the containerd image-store
// is used.
Containers string
// Plugins holds the default containerd namespace used for
// plugins managed by the daemon.
//
// The default namespace for plugins is "moby", but will be
// suffixed with the `<uid>.<gid>` of the remapped `root` if
// user-namespaces are enabled and the containerd image-store
// is used.
Plugins string
}
type legacyFields struct {
ExecutionDriver string `json:",omitempty"` // Deprecated: deprecated since API v1.25, but returned for older versions.
}

View File

@@ -1,8 +1,6 @@
package types // import "github.com/docker/docker/api/types"
import (
"io"
"os"
"time"
"github.com/docker/docker/api/types/container"
@@ -155,36 +153,13 @@ type Container struct {
State string
Status string
HostConfig struct {
NetworkMode string `json:",omitempty"`
NetworkMode string `json:",omitempty"`
Annotations map[string]string `json:",omitempty"`
}
NetworkSettings *SummaryNetworkSettings
Mounts []MountPoint
}
// CopyConfig contains request body of Engine API:
// POST "/containers/"+containerID+"/copy"
type CopyConfig struct {
Resource string
}
// ContainerPathStat is used to encode the header from
// GET "/containers/{name:.*}/archive"
// "Name" is the file or directory name.
type ContainerPathStat struct {
Name string `json:"name"`
Size int64 `json:"size"`
Mode os.FileMode `json:"mode"`
Mtime time.Time `json:"mtime"`
LinkTarget string `json:"linkTarget"`
}
// ContainerStats contains response of Engine API:
// GET "/stats"
type ContainerStats struct {
Body io.ReadCloser `json:"body"`
OSType string `json:"ostype"`
}
// Ping contains response of Engine API:
// GET "/_ping"
type Ping struct {
@@ -230,17 +205,6 @@ type Version struct {
BuildTime string `json:",omitempty"`
}
// ExecStartCheck is a temp struct used by execStart
// Config fields is part of ExecConfig in runconfig package
type ExecStartCheck struct {
// ExecStart will first check if it's detached
Detach bool
// Check if there's a tty
Tty bool
// Terminal size [height, width], unused if Tty == false
ConsoleSize *[2]uint `json:",omitempty"`
}
// HealthcheckResult stores information about a single run of a healthcheck probe
type HealthcheckResult struct {
Start time.Time // Start is the time this check started
@@ -281,18 +245,6 @@ type ContainerState struct {
Health *Health `json:",omitempty"`
}
// ContainerNode stores information about the node that a container
// is running on. It's only used by the Docker Swarm standalone API
type ContainerNode struct {
ID string
IPAddress string `json:"IP"`
Addr string
Name string
Cpus int
Memory int64
Labels map[string]string
}
// ContainerJSONBase contains response of Engine API:
// GET "/containers/{name:.*}/json"
type ContainerJSONBase struct {
@@ -306,7 +258,7 @@ type ContainerJSONBase struct {
HostnamePath string
HostsPath string
LogPath string
Node *ContainerNode `json:",omitempty"` // Node is only propagated by Docker Swarm standalone API
Node *ContainerNode `json:",omitempty"` // Deprecated: Node was only propagated by Docker Swarm standalone API. It sill be removed in the next release.
Name string
RestartCount int
Driver string
@@ -423,84 +375,6 @@ type MountPoint struct {
Propagation mount.Propagation
}
// NetworkResource is the body of the "get network" http response message
type NetworkResource struct {
Name string // Name is the requested name of the network
ID string `json:"Id"` // ID uniquely identifies a network on a single machine
Created time.Time // Created is the time the network created
Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level)
Driver string // Driver is the Driver name used to create the network (e.g. `bridge`, `overlay`)
EnableIPv6 bool // EnableIPv6 represents whether to enable IPv6
IPAM network.IPAM // IPAM is the network's IP Address Management
Internal bool // Internal represents if the network is used internal only
Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
ConfigFrom network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network.
ConfigOnly bool // ConfigOnly networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services.
Containers map[string]EndpointResource // Containers contains endpoints belonging to the network
Options map[string]string // Options holds the network specific options to use for when creating the network
Labels map[string]string // Labels holds metadata specific to the network being created
Peers []network.PeerInfo `json:",omitempty"` // List of peer nodes for an overlay network
Services map[string]network.ServiceInfo `json:",omitempty"`
}
// EndpointResource contains network resources allocated and used for a container in a network
type EndpointResource struct {
Name string
EndpointID string
MacAddress string
IPv4Address string
IPv6Address string
}
// NetworkCreate is the expected body of the "create network" http request message
type NetworkCreate struct {
// Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client
// package to older daemons.
CheckDuplicate bool `json:",omitempty"`
Driver string
Scope string
EnableIPv6 bool
IPAM *network.IPAM
Internal bool
Attachable bool
Ingress bool
ConfigOnly bool
ConfigFrom *network.ConfigReference
Options map[string]string
Labels map[string]string
}
// NetworkCreateRequest is the request message sent to the server for network create call.
type NetworkCreateRequest struct {
NetworkCreate
Name string
}
// NetworkCreateResponse is the response message sent by the server for network create call
type NetworkCreateResponse struct {
ID string `json:"Id"`
Warning string
}
// NetworkConnect represents the data to be used to connect a container to the network
type NetworkConnect struct {
Container string
EndpointConfig *network.EndpointSettings `json:",omitempty"`
}
// NetworkDisconnect represents the data to be used to disconnect a container from the network
type NetworkDisconnect struct {
Container string
Force bool
}
// NetworkInspectOptions holds parameters to inspect network
type NetworkInspectOptions struct {
Scope string
Verbose bool
}
// DiskUsageObject represents an object type used for disk usage query filtering.
type DiskUsageObject string
@@ -533,27 +407,6 @@ type DiskUsage struct {
BuilderSize int64 `json:",omitempty"` // Deprecated: deprecated in API 1.38, and no longer used since API 1.40.
}
// ContainersPruneReport contains the response for Engine API:
// POST "/containers/prune"
type ContainersPruneReport struct {
ContainersDeleted []string
SpaceReclaimed uint64
}
// VolumesPruneReport contains the response for Engine API:
// POST "/volumes/prune"
type VolumesPruneReport struct {
VolumesDeleted []string
SpaceReclaimed uint64
}
// ImagesPruneReport contains the response for Engine API:
// POST "/images/prune"
type ImagesPruneReport struct {
ImagesDeleted []image.DeleteResponse
SpaceReclaimed uint64
}
// BuildCachePruneReport contains the response for Engine API:
// POST "/build/prune"
type BuildCachePruneReport struct {
@@ -561,12 +414,6 @@ type BuildCachePruneReport struct {
SpaceReclaimed uint64
}
// NetworksPruneReport contains the response for Engine API:
// POST "/networks/prune"
type NetworksPruneReport struct {
NetworksDeleted []string
}
// SecretCreateResponse contains the information returned to a client
// on the creation of a new secret.
type SecretCreateResponse struct {

View File

@@ -1,35 +1,210 @@
package types
import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/volume"
)
// ImageImportOptions holds information to import images from the client host.
// ImagesPruneReport contains the response for Engine API:
// POST "/images/prune"
//
// Deprecated: use [image.ImportOptions].
type ImageImportOptions = image.ImportOptions
// Deprecated: use [image.PruneReport].
type ImagesPruneReport = image.PruneReport
// ImageCreateOptions holds information to create images.
// VolumesPruneReport contains the response for Engine API:
// POST "/volumes/prune".
//
// Deprecated: use [image.CreateOptions].
type ImageCreateOptions = image.CreateOptions
// Deprecated: use [volume.PruneReport].
type VolumesPruneReport = volume.PruneReport
// ImagePullOptions holds information to pull images.
// NetworkCreateRequest is the request message sent to the server for network create call.
//
// Deprecated: use [image.PullOptions].
type ImagePullOptions = image.PullOptions
// Deprecated: use [network.CreateRequest].
type NetworkCreateRequest = network.CreateRequest
// ImagePushOptions holds information to push images.
// NetworkCreate is the expected body of the "create network" http request message
//
// Deprecated: use [image.PushOptions].
type ImagePushOptions = image.PushOptions
// Deprecated: use [network.CreateOptions].
type NetworkCreate = network.CreateOptions
// ImageListOptions holds parameters to list images with.
// NetworkListOptions holds parameters to filter the list of networks with.
//
// Deprecated: use [image.ListOptions].
type ImageListOptions = image.ListOptions
// Deprecated: use [network.ListOptions].
type NetworkListOptions = network.ListOptions
// ImageRemoveOptions holds parameters to remove images.
// NetworkCreateResponse is the response message sent by the server for network create call.
//
// Deprecated: use [image.RemoveOptions].
type ImageRemoveOptions = image.RemoveOptions
// Deprecated: use [network.CreateResponse].
type NetworkCreateResponse = network.CreateResponse
// NetworkInspectOptions holds parameters to inspect network.
//
// Deprecated: use [network.InspectOptions].
type NetworkInspectOptions = network.InspectOptions
// NetworkConnect represents the data to be used to connect a container to the network
//
// Deprecated: use [network.ConnectOptions].
type NetworkConnect = network.ConnectOptions
// NetworkDisconnect represents the data to be used to disconnect a container from the network
//
// Deprecated: use [network.DisconnectOptions].
type NetworkDisconnect = network.DisconnectOptions
// EndpointResource contains network resources allocated and used for a container in a network.
//
// Deprecated: use [network.EndpointResource].
type EndpointResource = network.EndpointResource
// NetworkResource is the body of the "get network" http response message/
//
// Deprecated: use [network.Inspect] or [network.Summary] (for list operations).
type NetworkResource = network.Inspect
// NetworksPruneReport contains the response for Engine API:
// POST "/networks/prune"
//
// Deprecated: use [network.PruneReport].
type NetworksPruneReport = network.PruneReport
// ExecConfig is a small subset of the Config struct that holds the configuration
// for the exec feature of docker.
//
// Deprecated: use [container.ExecOptions].
type ExecConfig = container.ExecOptions
// ExecStartCheck is a temp struct used by execStart
// Config fields is part of ExecConfig in runconfig package
//
// Deprecated: use [container.ExecStartOptions] or [container.ExecAttachOptions].
type ExecStartCheck = container.ExecStartOptions
// ContainerExecInspect holds information returned by exec inspect.
//
// Deprecated: use [container.ExecInspect].
type ContainerExecInspect = container.ExecInspect
// ContainersPruneReport contains the response for Engine API:
// POST "/containers/prune"
//
// Deprecated: use [container.PruneReport].
type ContainersPruneReport = container.PruneReport
// ContainerPathStat is used to encode the header from
// GET "/containers/{name:.*}/archive"
// "Name" is the file or directory name.
//
// Deprecated: use [container.PathStat].
type ContainerPathStat = container.PathStat
// CopyToContainerOptions holds information
// about files to copy into a container.
//
// Deprecated: use [container.CopyToContainerOptions],
type CopyToContainerOptions = container.CopyToContainerOptions
// ContainerStats contains response of Engine API:
// GET "/stats"
//
// Deprecated: use [container.StatsResponseReader].
type ContainerStats = container.StatsResponseReader
// ThrottlingData stores CPU throttling stats of one running container.
// Not used on Windows.
//
// Deprecated: use [container.ThrottlingData].
type ThrottlingData = container.ThrottlingData
// CPUUsage stores All CPU stats aggregated since container inception.
//
// Deprecated: use [container.CPUUsage].
type CPUUsage = container.CPUUsage
// CPUStats aggregates and wraps all CPU related info of container
//
// Deprecated: use [container.CPUStats].
type CPUStats = container.CPUStats
// MemoryStats aggregates all memory stats since container inception on Linux.
// Windows returns stats for commit and private working set only.
//
// Deprecated: use [container.MemoryStats].
type MemoryStats = container.MemoryStats
// BlkioStatEntry is one small entity to store a piece of Blkio stats
// Not used on Windows.
//
// Deprecated: use [container.BlkioStatEntry].
type BlkioStatEntry = container.BlkioStatEntry
// BlkioStats stores All IO service stats for data read and write.
// This is a Linux specific structure as the differences between expressing
// block I/O on Windows and Linux are sufficiently significant to make
// little sense attempting to morph into a combined structure.
//
// Deprecated: use [container.BlkioStats].
type BlkioStats = container.BlkioStats
// StorageStats is the disk I/O stats for read/write on Windows.
//
// Deprecated: use [container.StorageStats].
type StorageStats = container.StorageStats
// NetworkStats aggregates the network stats of one container
//
// Deprecated: use [container.NetworkStats].
type NetworkStats = container.NetworkStats
// PidsStats contains the stats of a container's pids
//
// Deprecated: use [container.PidsStats].
type PidsStats = container.PidsStats
// Stats is Ultimate struct aggregating all types of stats of one container
//
// Deprecated: use [container.Stats].
type Stats = container.Stats
// StatsJSON is newly used Networks
//
// Deprecated: use [container.StatsResponse].
type StatsJSON = container.StatsResponse
// EventsOptions holds parameters to filter events with.
//
// Deprecated: use [events.ListOptions].
type EventsOptions = events.ListOptions
// ImageSearchOptions holds parameters to search images with.
//
// Deprecated: use [registry.SearchOptions].
type ImageSearchOptions = registry.SearchOptions
// ImageImportSource holds source information for ImageImport
//
// Deprecated: use [image.ImportSource].
type ImageImportSource image.ImportSource
// ImageLoadResponse returns information to the client about a load process.
//
// Deprecated: use [image.LoadResponse].
type ImageLoadResponse = image.LoadResponse
// ContainerNode stores information about the node that a container
// is running on. It's only used by the Docker Swarm standalone API.
//
// Deprecated: ContainerNode was used for the classic Docker Swarm standalone API. It will be removed in the next release.
type ContainerNode struct {
ID string
IPAddress string `json:"IP"`
Addr string
Name string
Cpus int
Memory int64
Labels map[string]string
}

View File

@@ -6,3 +6,10 @@ import "github.com/docker/docker/api/types/filters"
type ListOptions struct {
Filters filters.Args
}
// PruneReport contains the response for Engine API:
// POST "/volumes/prune"
type PruneReport struct {
VolumesDeleted []string
SpaceReclaimed uint64
}

View File

@@ -1,5 +1,5 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.19
//go:build go1.21
package containerimage
@@ -15,7 +15,6 @@ import (
"time"
"github.com/containerd/containerd/content"
cerrdefs "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/gc"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/leases"
@@ -25,6 +24,7 @@ import (
"github.com/containerd/containerd/remotes"
"github.com/containerd/containerd/remotes/docker"
"github.com/containerd/containerd/remotes/docker/schema1" //nolint:staticcheck // Ignore SA1019: "github.com/containerd/containerd/remotes/docker/schema1" is deprecated: use images formatted in Docker Image Manifest v2, Schema 2, or OCI Image Spec v1.
cerrdefs "github.com/containerd/errdefs"
"github.com/containerd/log"
distreference "github.com/distribution/reference"
dimages "github.com/docker/docker/daemon/images"

View File

@@ -7,10 +7,10 @@ import (
"strings"
"sync"
cerrdefs "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/snapshots"
cerrdefs "github.com/containerd/errdefs"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/layer"
"github.com/docker/docker/pkg/idtools"

View File

@@ -14,6 +14,7 @@ import (
"github.com/containerd/containerd/remotes/docker"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/api/types/container"
timetypes "github.com/docker/docker/api/types/time"
"github.com/docker/docker/builder"
"github.com/docker/docker/builder/builder-next/exporter"
@@ -21,11 +22,11 @@ import (
"github.com/docker/docker/builder/builder-next/exporter/overrides"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/daemon/images"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/libnetwork"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/go-units"
controlapi "github.com/moby/buildkit/api/services/control"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/control"
@@ -76,23 +77,24 @@ var cacheFields = map[string]bool{
// Opt is option struct required for creating the builder
type Opt struct {
SessionManager *session.Manager
Root string
EngineID string
Dist images.DistributionServices
ImageTagger mobyexporter.ImageTagger
NetworkController *libnetwork.Controller
DefaultCgroupParent string
RegistryHosts docker.RegistryHosts
BuilderConfig config.BuilderConfig
Rootless bool
IdentityMapping idtools.IdentityMapping
DNSConfig config.DNSConfig
ApparmorProfile string
UseSnapshotter bool
Snapshotter string
ContainerdAddress string
ContainerdNamespace string
SessionManager *session.Manager
Root string
EngineID string
Dist images.DistributionServices
ImageTagger mobyexporter.ImageTagger
NetworkController *libnetwork.Controller
DefaultCgroupParent string
RegistryHosts docker.RegistryHosts
BuilderConfig config.BuilderConfig
Rootless bool
IdentityMapping idtools.IdentityMapping
DNSConfig config.DNSConfig
ApparmorProfile string
UseSnapshotter bool
Snapshotter string
ContainerdAddress string
ContainerdNamespace string
ImageExportedCallback exporter.ImageExportedByBuildkit
}
// Builder can build using BuildKit backend
@@ -326,7 +328,7 @@ func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder.
// TODO: remove once opt.Options.Platform is of type specs.Platform
_, err := platforms.Parse(opt.Options.Platform)
if err != nil {
return nil, err
return nil, errdefs.InvalidParameter(err)
}
frontendAttrs["platform"] = opt.Options.Platform
}
@@ -391,7 +393,7 @@ func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder.
req := &controlapi.SolveRequest{
Ref: id,
Exporters: []*controlapi.Exporter{
&controlapi.Exporter{Type: exporterName, Attrs: exporterAttrs},
{Type: exporterName, Attrs: exporterAttrs},
},
Frontend: "dockerfile.v0",
FrontendAttrs: frontendAttrs,
@@ -611,7 +613,7 @@ func toBuildkitExtraHosts(inp []string, hostGatewayIP net.IP) (string, error) {
}
// toBuildkitUlimits converts ulimits from docker type=soft:hard format to buildkit's csv format
func toBuildkitUlimits(inp []*units.Ulimit) (string, error) {
func toBuildkitUlimits(inp []*container.Ulimit) (string, error) {
if len(inp) == 0 {
return "", nil
}

View File

@@ -46,6 +46,7 @@ import (
"github.com/moby/buildkit/util/archutil"
"github.com/moby/buildkit/util/entitlements"
"github.com/moby/buildkit/util/network/netproviders"
"github.com/moby/buildkit/util/tracing"
"github.com/moby/buildkit/util/tracing/detect"
"github.com/moby/buildkit/worker"
"github.com/moby/buildkit/worker/containerd"
@@ -67,11 +68,17 @@ func newController(ctx context.Context, rt http.RoundTripper, opt Opt) (*control
}
func getTraceExporter(ctx context.Context) trace.SpanExporter {
span, _, err := detect.Exporter()
if err != nil {
log.G(ctx).WithError(err).Error("Failed to detect trace exporter for buildkit controller")
tc := make(tracing.MultiSpanExporter, 0, 2)
if detect.Recorder != nil {
tc = append(tc, detect.Recorder)
}
return span
if exp, err := detect.NewSpanExporter(ctx); err != nil {
log.G(ctx).WithError(err).Error("Failed to detect trace exporter for buildkit controller")
} else if !detect.IsNoneSpanExporter(exp) {
tc = append(tc, exp)
}
return tc
}
func newSnapshotterController(ctx context.Context, rt http.RoundTripper, opt Opt) (*control.Controller, error) {
@@ -131,7 +138,7 @@ func newSnapshotterController(ctx context.Context, rt http.RoundTripper, opt Opt
}
wo.Executor = exec
w, err := mobyworker.NewContainerdWorker(ctx, wo)
w, err := mobyworker.NewContainerdWorker(ctx, wo, opt.ImageExportedCallback)
if err != nil {
return nil, err
}
@@ -142,9 +149,15 @@ func newSnapshotterController(ctx context.Context, rt http.RoundTripper, opt Opt
if err != nil {
return nil, err
}
gwf, err := gateway.NewGatewayFrontend(wc.Infos(), nil)
if err != nil {
return nil, err
}
frontends := map[string]frontend.Frontend{
"dockerfile.v0": forwarder.NewGatewayForwarder(wc.Infos(), dockerfile.Build),
"gateway.v0": gateway.NewGatewayFrontend(wc.Infos()),
"gateway.v0": gwf,
}
return control.NewController(control.Opt{
@@ -303,11 +316,12 @@ func newGraphDriverController(ctx context.Context, rt http.RoundTripper, opt Opt
}
exp, err := mobyexporter.New(mobyexporter.Opt{
ImageStore: dist.ImageStore,
ContentStore: store,
Differ: differ,
ImageTagger: opt.ImageTagger,
LeaseManager: lm,
ImageStore: dist.ImageStore,
ContentStore: store,
Differ: differ,
ImageTagger: opt.ImageTagger,
LeaseManager: lm,
ImageExportedCallback: opt.ImageExportedCallback,
})
if err != nil {
return nil, err
@@ -366,9 +380,14 @@ func newGraphDriverController(ctx context.Context, rt http.RoundTripper, opt Opt
}
wc.Add(w)
gwf, err := gateway.NewGatewayFrontend(wc.Infos(), nil)
if err != nil {
return nil, err
}
frontends := map[string]frontend.Frontend{
"dockerfile.v0": forwarder.NewGatewayForwarder(wc.Infos(), dockerfile.Build),
"gateway.v0": gateway.NewGatewayFrontend(wc.Infos()),
"gateway.v0": gwf,
}
return control.NewController(control.Opt{

View File

@@ -113,20 +113,20 @@ func (iface *lnInterface) init(c *libnetwork.Controller, n *libnetwork.Network)
defer close(iface.ready)
id := identity.NewID()
ep, err := n.CreateEndpoint(id, libnetwork.CreateOptionDisableResolution())
ep, err := n.CreateEndpoint(context.TODO(), id, libnetwork.CreateOptionDisableResolution())
if err != nil {
iface.err = err
return
}
sbx, err := c.NewSandbox(id, libnetwork.OptionUseExternalKey(), libnetwork.OptionHostsPath(filepath.Join(iface.provider.Root, id, "hosts")),
sbx, err := c.NewSandbox(context.TODO(), id, libnetwork.OptionUseExternalKey(), libnetwork.OptionHostsPath(filepath.Join(iface.provider.Root, id, "hosts")),
libnetwork.OptionResolvConfPath(filepath.Join(iface.provider.Root, id, "resolv.conf")))
if err != nil {
iface.err = err
return
}
if err := ep.Join(sbx); err != nil {
if err := ep.Join(context.TODO(), sbx); err != nil {
iface.err = err
return
}
@@ -161,7 +161,7 @@ func (iface *lnInterface) Close() error {
<-iface.ready
if iface.sbx != nil {
go func() {
if err := iface.sbx.Delete(); err != nil {
if err := iface.sbx.Delete(context.TODO()); err != nil {
log.G(context.TODO()).WithError(err).Errorf("failed to delete builder network sandbox")
}
if err := os.RemoveAll(filepath.Join(iface.provider.Root, iface.sbx.ContainerID())); err != nil {

View File

@@ -22,11 +22,11 @@ func newExecutor(_, _ string, _ *libnetwork.Controller, _ *oci.DNSConfig, _ bool
type stubExecutor struct{}
func (w *stubExecutor) Run(ctx context.Context, id string, root executor.Mount, mounts []executor.Mount, process executor.ProcessInfo, started chan<- struct{}) (resourcetypes.Recorder, error) {
return nil, errors.New("buildkit executor not implemented for "+runtime.GOOS)
return nil, errors.New("buildkit executor not implemented for " + runtime.GOOS)
}
func (w *stubExecutor) Exec(ctx context.Context, id string, process executor.ProcessInfo) error {
return errors.New("buildkit executor not implemented for "+runtime.GOOS)
return errors.New("buildkit executor not implemented for " + runtime.GOOS)
}
func getDNSConfig(config.DNSConfig) *oci.DNSConfig {

View File

@@ -10,8 +10,8 @@ import (
"github.com/containerd/containerd/leases"
"github.com/containerd/log"
distref "github.com/distribution/reference"
builderexporter "github.com/docker/docker/builder/builder-next/exporter"
"github.com/docker/docker/image"
"github.com/docker/docker/internal/compatcontext"
"github.com/docker/docker/layer"
"github.com/moby/buildkit/exporter"
"github.com/moby/buildkit/exporter/containerimage"
@@ -33,11 +33,12 @@ type ImageTagger interface {
// Opt defines a struct for creating new exporter
type Opt struct {
ImageStore image.Store
Differ Differ
ImageTagger ImageTagger
ContentStore content.Store
LeaseManager leases.Manager
ImageStore image.Store
Differ Differ
ImageTagger ImageTagger
ContentStore content.Store
LeaseManager leases.Manager
ImageExportedCallback builderexporter.ImageExportedByBuildkit
}
type imageExporter struct {
@@ -50,12 +51,13 @@ func New(opt Opt) (exporter.Exporter, error) {
return im, nil
}
func (e *imageExporter) Resolve(ctx context.Context, id int, opt map[string]string) (exporter.ExporterInstance, error) {
func (e *imageExporter) Resolve(ctx context.Context, id int, attrs map[string]string) (exporter.ExporterInstance, error) {
i := &imageExporterInstance{
imageExporter: e,
id: id,
attrs: attrs,
}
for k, v := range opt {
for k, v := range attrs {
switch exptypes.ImageExporterOptKey(k) {
case exptypes.OptKeyName:
for _, v := range strings.Split(v, ",") {
@@ -80,12 +82,17 @@ type imageExporterInstance struct {
id int
targetNames []distref.Named
meta map[string][]byte
attrs map[string]string
}
func (e *imageExporterInstance) ID() int {
return e.id
}
func (e *imageExporterInstance) Type() string {
return "image"
}
func (e *imageExporterInstance) Name() string {
return "exporting to image"
}
@@ -94,6 +101,10 @@ func (e *imageExporterInstance) Config() *exporter.Config {
return exporter.NewConfig()
}
func (e *imageExporterInstance) Attrs() map[string]string {
return e.attrs
}
func (e *imageExporterInstance) Export(ctx context.Context, inp *exporter.Source, inlineCache exptypes.InlineCache, sessionID string) (map[string]string, exporter.DescriptorReference, error) {
if len(inp.Refs) > 1 {
return nil, nil, fmt.Errorf("exporting multiple references to image store is currently unsupported")
@@ -217,6 +228,10 @@ func (e *imageExporterInstance) Export(ctx context.Context, inp *exporter.Source
return nil, nil, fmt.Errorf("failed to create a temporary descriptor reference: %w", err)
}
if e.opt.ImageExportedCallback != nil {
e.opt.ImageExportedCallback(ctx, id.String(), descRef.Descriptor())
}
return resp, descRef, nil
}
@@ -230,7 +245,7 @@ func (e *imageExporterInstance) newTempReference(ctx context.Context, config []b
}
unlease := func(ctx context.Context) error {
err := done(compatcontext.WithoutCancel(ctx))
err := done(context.WithoutCancel(ctx))
if err != nil {
log.G(ctx).WithError(err).Error("failed to delete descriptor reference lease")
}

View File

@@ -45,6 +45,10 @@ func patchImageConfig(dt []byte, dps []digest.Digest, history []ocispec.History,
return nil, errors.Wrap(err, "failed to parse image config for patch")
}
if m == nil {
return nil, errors.New("null image config")
}
var rootFS ocispec.RootFS
rootFS.Type = "layers"
rootFS.DiffIDs = append(rootFS.DiffIDs, dps...)

View File

@@ -0,0 +1,42 @@
package mobyexporter
import (
"testing"
"gotest.tools/v3/assert"
)
func TestPatchImageConfig(t *testing.T) {
for _, tc := range []struct {
name string
cfgJSON string
err string
}{
{
name: "empty",
cfgJSON: "{}",
},
{
name: "history only",
cfgJSON: `{"history": []}`,
},
{
name: "rootfs only",
cfgJSON: `{"rootfs": {}}`,
},
{
name: "null",
cfgJSON: "null",
err: "null image config",
},
} {
t.Run(tc.name, func(t *testing.T) {
_, err := patchImageConfig([]byte(tc.cfgJSON), nil, nil, nil)
if tc.err == "" {
assert.NilError(t, err)
} else {
assert.ErrorContains(t, err, tc.err)
}
})
}
}

View File

@@ -1,37 +0,0 @@
package overrides
import (
"context"
"strings"
"github.com/moby/buildkit/exporter"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
)
// Wraps the containerimage exporter's Resolve method to apply moby-specific
// overrides to the exporter attributes.
type imageExporterMobyWrapper struct {
exp exporter.Exporter
}
func NewExporterWrapper(exp exporter.Exporter) (exporter.Exporter, error) {
return &imageExporterMobyWrapper{exp: exp}, nil
}
// Resolve applies moby specific attributes to the request.
func (e *imageExporterMobyWrapper) Resolve(ctx context.Context, id int, exporterAttrs map[string]string) (exporter.ExporterInstance, error) {
if exporterAttrs == nil {
exporterAttrs = make(map[string]string)
}
reposAndTags, err := SanitizeRepoAndTags(strings.Split(exporterAttrs[string(exptypes.OptKeyName)], ","))
if err != nil {
return nil, err
}
exporterAttrs[string(exptypes.OptKeyName)] = strings.Join(reposAndTags, ",")
exporterAttrs[string(exptypes.OptKeyUnpack)] = "true"
if _, has := exporterAttrs[string(exptypes.OptKeyDanglingPrefix)]; !has {
exporterAttrs[string(exptypes.OptKeyDanglingPrefix)] = "moby-dangling"
}
return e.exp.Resolve(ctx, id, exporterAttrs)
}

View File

@@ -0,0 +1,69 @@
package exporter
import (
"context"
"strings"
"github.com/docker/docker/builder/builder-next/exporter/overrides"
"github.com/moby/buildkit/exporter"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
type ImageExportedByBuildkit = func(ctx context.Context, id string, desc ocispec.Descriptor) error
// Wraps the containerimage exporter's Resolve method to apply moby-specific
// overrides to the exporter attributes.
type imageExporterMobyWrapper struct {
exp exporter.Exporter
callback ImageExportedByBuildkit
}
// NewWrapper returns an exporter wrapper that applies moby specific attributes
// and hooks the export process.
func NewWrapper(exp exporter.Exporter, callback ImageExportedByBuildkit) (exporter.Exporter, error) {
return &imageExporterMobyWrapper{exp: exp, callback: callback}, nil
}
// Resolve applies moby specific attributes to the request.
func (e *imageExporterMobyWrapper) Resolve(ctx context.Context, id int, exporterAttrs map[string]string) (exporter.ExporterInstance, error) {
if exporterAttrs == nil {
exporterAttrs = make(map[string]string)
}
reposAndTags, err := overrides.SanitizeRepoAndTags(strings.Split(exporterAttrs[string(exptypes.OptKeyName)], ","))
if err != nil {
return nil, err
}
exporterAttrs[string(exptypes.OptKeyName)] = strings.Join(reposAndTags, ",")
exporterAttrs[string(exptypes.OptKeyUnpack)] = "true"
if _, has := exporterAttrs[string(exptypes.OptKeyDanglingPrefix)]; !has {
exporterAttrs[string(exptypes.OptKeyDanglingPrefix)] = "moby-dangling"
}
inst, err := e.exp.Resolve(ctx, id, exporterAttrs)
if err != nil {
return nil, err
}
return &imageExporterInstanceWrapper{ExporterInstance: inst, callback: e.callback}, nil
}
type imageExporterInstanceWrapper struct {
exporter.ExporterInstance
callback ImageExportedByBuildkit
}
func (i *imageExporterInstanceWrapper) Export(ctx context.Context, src *exporter.Source, inlineCache exptypes.InlineCache, sessionID string) (map[string]string, exporter.DescriptorReference, error) {
out, ref, err := i.ExporterInstance.Export(ctx, src, inlineCache, sessionID)
if err != nil {
return out, ref, err
}
desc := ref.Descriptor()
imageID := out[exptypes.ExporterImageDigestKey]
if i.callback != nil {
i.callback(ctx, imageID, desc)
}
return out, ref, nil
}

View File

@@ -4,7 +4,6 @@ import (
"context"
mobyexporter "github.com/docker/docker/builder/builder-next/exporter"
"github.com/docker/docker/builder/builder-next/exporter/overrides"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/exporter"
"github.com/moby/buildkit/session"
@@ -14,15 +13,16 @@ import (
// ContainerdWorker is a local worker instance with dedicated snapshotter, cache, and so on.
type ContainerdWorker struct {
*base.Worker
callback mobyexporter.ImageExportedByBuildkit
}
// NewContainerdWorker instantiates a local worker.
func NewContainerdWorker(ctx context.Context, wo base.WorkerOpt) (*ContainerdWorker, error) {
func NewContainerdWorker(ctx context.Context, wo base.WorkerOpt, callback mobyexporter.ImageExportedByBuildkit) (*ContainerdWorker, error) {
bw, err := base.NewWorker(ctx, wo)
if err != nil {
return nil, err
}
return &ContainerdWorker{Worker: bw}, nil
return &ContainerdWorker{Worker: bw, callback: callback}, nil
}
// Exporter returns exporter by name
@@ -33,7 +33,7 @@ func (w *ContainerdWorker) Exporter(name string, sm *session.Manager) (exporter.
if err != nil {
return nil, err
}
return overrides.NewExporterWrapper(exp)
return mobyexporter.NewWrapper(exp, w.callback)
default:
return w.Worker.Exporter(name, sm)
}

View File

@@ -4,8 +4,6 @@ import (
"fmt"
"io"
"sort"
"github.com/docker/docker/runconfig/opts"
)
// builtinAllowedBuildArgs is list of built-in allowed build args
@@ -138,7 +136,7 @@ func (b *BuildArgs) getAllFromMapping(source map[string]*string) map[string]stri
// FilterAllowed returns all allowed args without the filtered args
func (b *BuildArgs) FilterAllowed(filter []string) []string {
envs := []string{}
configEnv := opts.ConvertKVStringsToMap(filter)
configEnv := convertKVStringsToMap(filter)
for key, val := range b.GetAllAllowed() {
if _, ok := configEnv[key]; !ok {

View File

@@ -159,7 +159,7 @@ func newBuilder(ctx context.Context, options builderOptions) (*Builder, error) {
if config.Platform != "" {
sp, err := platforms.Parse(config.Platform)
if err != nil {
return nil, err
return nil, errdefs.InvalidParameter(err)
}
b.platform = &sp
}
@@ -187,7 +187,7 @@ func buildLabelOptions(labels map[string]string, stages []instructions.Stage) {
func (b *Builder) build(ctx context.Context, source builder.Source, dockerfile *parser.Result) (*builder.Result, error) {
defer b.imageSources.Unmount()
stages, metaArgs, err := instructions.Parse(dockerfile.AST)
stages, metaArgs, err := instructions.Parse(dockerfile.AST, nil)
if err != nil {
var uiErr *instructions.UnknownInstructionError
if errors.As(err, &uiErr) {
@@ -230,7 +230,8 @@ func processMetaArg(meta instructions.ArgCommand, shlex *shell.Lex, args *BuildA
// shell.Lex currently only support the concatenated string format
envs := convertMapToEnvList(args.GetAllAllowed())
if err := meta.Expand(func(word string) (string, error) {
return shlex.ProcessWord(word, envs)
newword, _, err := shlex.ProcessWord(word, envs)
return newword, err
}); err != nil {
return err
}
@@ -380,3 +381,14 @@ func convertMapToEnvList(m map[string]string) []string {
}
return result
}
// convertKVStringsToMap converts ["key=value"] to {"key":"value"}
func convertKVStringsToMap(values []string) map[string]string {
result := make(map[string]string, len(values))
for _, value := range values {
k, v, _ := strings.Cut(value, "=")
result[k] = v
}
return result
}

View File

@@ -477,7 +477,7 @@ func performCopyForInfo(dest copyInfo, source copyInfo, options copyFileOptions)
}
// dest.path must be used because destPath has already been cleaned of any
// trailing slash
if endsInSlash(dest.path) || destExistsAsDir {
if destExistsAsDir || strings.HasSuffix(dest.path, string(os.PathSeparator)) {
// source.path must be used to get the correct filename when the source
// is a symlink
destPath = filepath.Join(destPath, filepath.Base(source.path))
@@ -524,10 +524,6 @@ func copyFile(archiver *archive.Archiver, source, dest string, identity *idtools
return nil
}
func endsInSlash(path string) bool {
return strings.HasSuffix(path, string(filepath.Separator))
}
// isExistingDirectory returns true if the path exists and is a directory
func isExistingDirectory(path string) (bool, error) {
destStat, err := os.Stat(path)

View File

@@ -166,17 +166,17 @@ func initializeStage(ctx context.Context, d dispatchRequest, cmd *instructions.S
p, err := platforms.Parse(v)
if err != nil {
return errors.Wrapf(err, "failed to parse platform %s", v)
return errors.Wrapf(errdefs.InvalidParameter(err), "failed to parse platform %s", v)
}
platform = &p
}
image, err := d.getFromImage(ctx, d.shlex, cmd.BaseName, platform)
img, err := d.getFromImage(ctx, d.shlex, cmd.BaseName, platform)
if err != nil {
return err
}
state := d.state
if err := state.beginStage(cmd.Name, image); err != nil {
if err := state.beginStage(cmd.Name, img); err != nil {
return err
}
if len(state.runConfig.OnBuild) > 0 {
@@ -224,7 +224,7 @@ func (d *dispatchRequest) getExpandedString(shlex *shell.Lex, str string) (strin
substitutionArgs = append(substitutionArgs, key+"="+value)
}
name, err := shlex.ProcessWord(str, substitutionArgs)
name, _, err := shlex.ProcessWord(str, substitutionArgs)
if err != nil {
return "", err
}

View File

@@ -30,7 +30,6 @@ import (
"github.com/docker/docker/errdefs"
"github.com/docker/docker/image"
"github.com/docker/docker/oci"
"github.com/docker/docker/runconfig/opts"
"github.com/moby/buildkit/frontend/dockerfile/instructions"
"github.com/moby/buildkit/frontend/dockerfile/shell"
"github.com/pkg/errors"
@@ -48,7 +47,8 @@ func dispatch(ctx context.Context, d dispatchRequest, cmd instructions.Command)
if ex, ok := cmd.(instructions.SupportsSingleWordExpansion); ok {
err := ex.Expand(func(word string) (string, error) {
return d.shlex.ProcessWord(word, envs)
newword, _, err := d.shlex.ProcessWord(word, envs)
return newword, err
})
if err != nil {
return errdefs.InvalidParameter(err)
@@ -242,7 +242,7 @@ func (s *dispatchState) setDefaultPath() {
if defaultPath == "" {
return
}
envMap := opts.ConvertKVStringsToMap(s.runConfig.Env)
envMap := convertKVStringsToMap(s.runConfig.Env)
if _, ok := envMap["PATH"]; !ok {
s.runConfig.Env = append(s.runConfig.Env, "PATH="+defaultPath)
}

View File

@@ -17,11 +17,11 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/builder"
networkSettings "github.com/docker/docker/daemon/network"
"github.com/docker/docker/image"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/chrootarchive"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/runconfig"
"github.com/docker/go-connections/nat"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
@@ -130,26 +130,24 @@ func (b *Builder) performCopy(ctx context.Context, req dispatchRequest, inst cop
commentStr := fmt.Sprintf("%s %s%s in %s ", inst.cmdName, chownComment, srcHash, inst.dest)
// TODO: should this have been using origPaths instead of srcHash in the comment?
runConfigWithCommentCmd := copyRunConfig(
state.runConfig,
withCmdCommentString(commentStr, state.operatingSystem))
runConfigWithCommentCmd := copyRunConfig(state.runConfig, withCmdCommentString(commentStr, state.operatingSystem))
hit, err := b.probeCache(state, runConfigWithCommentCmd)
if err != nil || hit {
return err
}
imageMount, err := b.imageSources.Get(ctx, state.imageID, true, req.builder.platform)
imgMount, err := b.imageSources.Get(ctx, state.imageID, true, req.builder.platform)
if err != nil {
return errors.Wrapf(err, "failed to get destination image %q", state.imageID)
}
rwLayer, err := imageMount.NewRWLayer()
rwLayer, err := imgMount.NewRWLayer()
if err != nil {
return err
}
defer rwLayer.Release()
destInfo, err := createDestInfo(state.runConfig.WorkingDir, inst, rwLayer, state.operatingSystem)
destInfo, err := createDestInfo(state.runConfig.WorkingDir, inst, rwLayer)
if err != nil {
return err
}
@@ -181,10 +179,10 @@ func (b *Builder) performCopy(ctx context.Context, req dispatchRequest, inst cop
return errors.Wrapf(err, "failed to copy files")
}
}
return b.exportImage(ctx, state, rwLayer, imageMount.Image(), runConfigWithCommentCmd)
return b.exportImage(ctx, state, rwLayer, imgMount.Image(), runConfigWithCommentCmd)
}
func createDestInfo(workingDir string, inst copyInstruction, rwLayer builder.RWLayer, platform string) (copyInfo, error) {
func createDestInfo(workingDir string, inst copyInstruction, rwLayer builder.RWLayer) (copyInfo, error) {
// Twiddle the destination when it's a relative path - meaning, make it
// relative to the WORKINGDIR
dest, err := normalizeDest(workingDir, inst.dest)
@@ -280,38 +278,38 @@ func withoutHealthcheck() runConfigModifier {
}
func copyRunConfig(runConfig *container.Config, modifiers ...runConfigModifier) *container.Config {
copy := *runConfig
copy.Cmd = copyStringSlice(runConfig.Cmd)
copy.Env = copyStringSlice(runConfig.Env)
copy.Entrypoint = copyStringSlice(runConfig.Entrypoint)
copy.OnBuild = copyStringSlice(runConfig.OnBuild)
copy.Shell = copyStringSlice(runConfig.Shell)
cfgCopy := *runConfig
cfgCopy.Cmd = copyStringSlice(runConfig.Cmd)
cfgCopy.Env = copyStringSlice(runConfig.Env)
cfgCopy.Entrypoint = copyStringSlice(runConfig.Entrypoint)
cfgCopy.OnBuild = copyStringSlice(runConfig.OnBuild)
cfgCopy.Shell = copyStringSlice(runConfig.Shell)
if copy.Volumes != nil {
copy.Volumes = make(map[string]struct{}, len(runConfig.Volumes))
if cfgCopy.Volumes != nil {
cfgCopy.Volumes = make(map[string]struct{}, len(runConfig.Volumes))
for k, v := range runConfig.Volumes {
copy.Volumes[k] = v
cfgCopy.Volumes[k] = v
}
}
if copy.ExposedPorts != nil {
copy.ExposedPorts = make(nat.PortSet, len(runConfig.ExposedPorts))
if cfgCopy.ExposedPorts != nil {
cfgCopy.ExposedPorts = make(nat.PortSet, len(runConfig.ExposedPorts))
for k, v := range runConfig.ExposedPorts {
copy.ExposedPorts[k] = v
cfgCopy.ExposedPorts[k] = v
}
}
if copy.Labels != nil {
copy.Labels = make(map[string]string, len(runConfig.Labels))
if cfgCopy.Labels != nil {
cfgCopy.Labels = make(map[string]string, len(runConfig.Labels))
for k, v := range runConfig.Labels {
copy.Labels[k] = v
cfgCopy.Labels[k] = v
}
}
for _, modifier := range modifiers {
modifier(&copy)
modifier(&cfgCopy)
}
return &copy
return &cfgCopy
}
func copyStringSlice(orig []string) []string {
@@ -335,7 +333,7 @@ func (b *Builder) probeCache(dispatchState *dispatchState, runConfig *container.
if cachedID == "" || err != nil {
return false, err
}
fmt.Fprint(b.Stdout, " ---> Using cache\n")
_, _ = fmt.Fprintln(b.Stdout, " ---> Using cache")
dispatchState.imageID = cachedID
return true, nil
@@ -354,16 +352,15 @@ func (b *Builder) create(ctx context.Context, runConfig *container.Config) (stri
log.G(ctx).Debugf("[BUILDER] Command to be executed: %v", runConfig.Cmd)
hostConfig := hostConfigFromOptions(b.options)
container, err := b.containerManager.Create(ctx, runConfig, hostConfig)
ctr, err := b.containerManager.Create(ctx, runConfig, hostConfig)
if err != nil {
return "", err
}
// TODO: could this be moved into containerManager.Create() ?
for _, warning := range container.Warnings {
fmt.Fprintf(b.Stdout, " ---> [Warning] %s\n", warning)
for _, warning := range ctr.Warnings {
_, _ = fmt.Fprintf(b.Stdout, " ---> [Warning] %s\n", warning)
}
fmt.Fprintf(b.Stdout, " ---> Running in %s\n", stringid.TruncateID(container.ID))
return container.ID, nil
_, _ = fmt.Fprintf(b.Stdout, " ---> Running in %s\n", stringid.TruncateID(ctr.ID))
return ctr.ID, nil
}
func hostConfigFromOptions(options *types.ImageBuildOptions) *container.HostConfig {
@@ -385,7 +382,7 @@ func hostConfigFromOptions(options *types.ImageBuildOptions) *container.HostConf
// This is in line with what the ContainerCreate API endpoint does.
networkMode := options.NetworkMode
if networkMode == "" || networkMode == network.NetworkDefault {
networkMode = runconfig.DefaultDaemonNetworkMode().NetworkName()
networkMode = networkSettings.DefaultNetwork
}
hc := &container.HostConfig{

View File

@@ -10,6 +10,7 @@ import (
"github.com/containerd/containerd/platforms"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/jsonmessage"
"golang.org/x/sys/windows"
@@ -62,7 +63,7 @@ func lookupNTAccount(ctx context.Context, builder *Builder, accountName string,
optionsPlatform, err := platforms.Parse(builder.options.Platform)
if err != nil {
return idtools.Identity{}, err
return idtools.Identity{}, errdefs.InvalidParameter(err)
}
runConfig := copyRunConfig(state.runConfig,

View File

@@ -44,8 +44,8 @@ func downloadRemote(remoteURL string) (string, io.ReadCloser, error) {
// GetWithStatusError does an http.Get() and returns an error if the
// status code is 4xx or 5xx.
func GetWithStatusError(address string) (resp *http.Response, err error) {
// #nosec G107
if resp, err = http.Get(address); err != nil {
resp, err = http.Get(address) // #nosec G107 -- ignore G107: Potential HTTP request made with variable url
if err != nil {
if uerr, ok := err.(*url.Error); ok {
if derr, ok := uerr.Err.(*net.DNSError); ok && !derr.IsTimeout {
return nil, errdefs.NotFound(err)

View File

@@ -49,6 +49,8 @@ import (
"net/url"
"path"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/docker/docker/api"
@@ -131,7 +133,10 @@ type Client struct {
negotiateVersion bool
// negotiated indicates that API version negotiation took place
negotiated bool
negotiated atomic.Bool
// negotiateLock is used to single-flight the version negotiation process
negotiateLock sync.Mutex
tp trace.TracerProvider
@@ -266,7 +271,16 @@ func (cli *Client) Close() error {
// be negotiated when making the actual requests, and for which cases
// we cannot do the negotiation lazily.
func (cli *Client) checkVersion(ctx context.Context) error {
if !cli.manualOverride && cli.negotiateVersion && !cli.negotiated {
if !cli.manualOverride && cli.negotiateVersion && !cli.negotiated.Load() {
// Ensure exclusive write access to version and negotiated fields
cli.negotiateLock.Lock()
defer cli.negotiateLock.Unlock()
// May have been set during last execution of critical zone
if cli.negotiated.Load() {
return nil
}
ping, err := cli.Ping(ctx)
if err != nil {
return err
@@ -312,6 +326,10 @@ func (cli *Client) ClientVersion() string {
// added (1.24).
func (cli *Client) NegotiateAPIVersion(ctx context.Context) {
if !cli.manualOverride {
// Avoid concurrent modification of version-related fields
cli.negotiateLock.Lock()
defer cli.negotiateLock.Unlock()
ping, err := cli.Ping(ctx)
if err != nil {
// FIXME(thaJeztah): Ping returns an error when failing to connect to the API; we should not swallow the error here, and instead returning it.
@@ -336,6 +354,10 @@ func (cli *Client) NegotiateAPIVersion(ctx context.Context) {
// added (1.24).
func (cli *Client) NegotiateAPIVersionPing(pingResponse types.Ping) {
if !cli.manualOverride {
// Avoid concurrent modification of version-related fields
cli.negotiateLock.Lock()
defer cli.negotiateLock.Unlock()
cli.negotiateAPIVersionPing(pingResponse)
}
}
@@ -361,7 +383,7 @@ func (cli *Client) negotiateAPIVersionPing(pingResponse types.Ping) {
// Store the results, so that automatic API version negotiation (if enabled)
// won't be performed on the next request.
if cli.negotiateVersion {
cli.negotiated = true
cli.negotiated.Store(true)
}
}

View File

@@ -342,7 +342,7 @@ func TestNegotiateAPIVersion(t *testing.T) {
// TestNegotiateAPIVersionOverride asserts that we honor the DOCKER_API_VERSION
// environment variable when negotiating versions.
func TestNegotiateAPVersionOverride(t *testing.T) {
func TestNegotiateAPIVersionOverride(t *testing.T) {
const expected = "9.99"
t.Setenv("DOCKER_API_VERSION", expected)
@@ -354,9 +354,9 @@ func TestNegotiateAPVersionOverride(t *testing.T) {
assert.Equal(t, client.ClientVersion(), expected)
}
// TestNegotiateAPVersionConnectionFailure asserts that we do not modify the
// TestNegotiateAPIVersionConnectionFailure asserts that we do not modify the
// API version when failing to connect.
func TestNegotiateAPVersionConnectionFailure(t *testing.T) {
func TestNegotiateAPIVersionConnectionFailure(t *testing.T) {
const expected = "9.99"
client, err := NewClientWithOpts(WithHost("tcp://no-such-host.invalid"))

View File

@@ -11,11 +11,11 @@ import (
"path/filepath"
"strings"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
)
// ContainerStatPath returns stat information about a path inside the container filesystem.
func (cli *Client) ContainerStatPath(ctx context.Context, containerID, path string) (types.ContainerPathStat, error) {
func (cli *Client) ContainerStatPath(ctx context.Context, containerID, path string) (container.PathStat, error) {
query := url.Values{}
query.Set("path", filepath.ToSlash(path)) // Normalize the paths used in the API.
@@ -23,14 +23,14 @@ func (cli *Client) ContainerStatPath(ctx context.Context, containerID, path stri
response, err := cli.head(ctx, urlStr, query, nil)
defer ensureReaderClosed(response)
if err != nil {
return types.ContainerPathStat{}, err
return container.PathStat{}, err
}
return getContainerPathStatFromHeader(response.header)
}
// CopyToContainer copies content into the container filesystem.
// Note that `content` must be a Reader for a TAR archive
func (cli *Client) CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader, options types.CopyToContainerOptions) error {
func (cli *Client) CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader, options container.CopyToContainerOptions) error {
query := url.Values{}
query.Set("path", filepath.ToSlash(dstPath)) // Normalize the paths used in the API.
// Do not allow for an existing directory to be overwritten by a non-directory and vice versa.
@@ -55,14 +55,14 @@ func (cli *Client) CopyToContainer(ctx context.Context, containerID, dstPath str
// CopyFromContainer gets the content from the container and returns it as a Reader
// for a TAR archive to manipulate it in the host. It's up to the caller to close the reader.
func (cli *Client) CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
func (cli *Client) CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, container.PathStat, error) {
query := make(url.Values, 1)
query.Set("path", filepath.ToSlash(srcPath)) // Normalize the paths used in the API.
apiPath := "/containers/" + containerID + "/archive"
response, err := cli.get(ctx, apiPath, query, nil)
if err != nil {
return nil, types.ContainerPathStat{}, err
return nil, container.PathStat{}, err
}
// In order to get the copy behavior right, we need to know information
@@ -78,8 +78,8 @@ func (cli *Client) CopyFromContainer(ctx context.Context, containerID, srcPath s
return response.body, stat, err
}
func getContainerPathStatFromHeader(header http.Header) (types.ContainerPathStat, error) {
var stat types.ContainerPathStat
func getContainerPathStatFromHeader(header http.Header) (container.PathStat, error) {
var stat container.PathStat
encodedStat := header.Get("X-Docker-Container-Path-Stat")
statDecoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(encodedStat))

View File

@@ -11,7 +11,7 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/errdefs"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@@ -64,7 +64,7 @@ func TestContainerStatPath(t *testing.T) {
if path != expectedPath {
return nil, fmt.Errorf("path not set in URL query properly")
}
content, err := json.Marshal(types.ContainerPathStat{
content, err := json.Marshal(container.PathStat{
Name: "name",
Mode: 0o700,
})
@@ -97,7 +97,7 @@ func TestCopyToContainerError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), container.CopyToContainerOptions{})
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
}
@@ -105,7 +105,7 @@ func TestCopyToContainerNotFoundError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusNotFound, "Not found")),
}
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), container.CopyToContainerOptions{})
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
}
@@ -115,7 +115,7 @@ func TestCopyToContainerEmptyResponse(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusNoContent, "No content")),
}
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), container.CopyToContainerOptions{})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -159,7 +159,7 @@ func TestCopyToContainer(t *testing.T) {
}, nil
}),
}
err := client.CopyToContainer(context.Background(), "container_id", expectedPath, bytes.NewReader([]byte("content")), types.CopyToContainerOptions{
err := client.CopyToContainer(context.Background(), "container_id", expectedPath, bytes.NewReader([]byte("content")), container.CopyToContainerOptions{
AllowOverwriteDirWithFile: false,
})
if err != nil {
@@ -188,7 +188,7 @@ func TestCopyFromContainerNotFoundError(t *testing.T) {
func TestCopyFromContainerEmptyResponse(t *testing.T) {
client := &Client{
client: newMockClient(func(req *http.Request) (*http.Response, error) {
content, err := json.Marshal(types.ContainerPathStat{
content, err := json.Marshal(container.PathStat{
Name: "path/to/file",
Mode: 0o700,
})
@@ -242,7 +242,7 @@ func TestCopyFromContainer(t *testing.T) {
return nil, fmt.Errorf("path not set in URL query properly, expected '%s', got %s", expectedPath, path)
}
headercontent, err := json.Marshal(types.ContainerPathStat{
headercontent, err := json.Marshal(container.PathStat{
Name: "name",
Mode: 0o700,
})

View File

@@ -6,11 +6,12 @@ import (
"net/http"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/versions"
)
// ContainerExecCreate creates a new exec configuration to run an exec process.
func (cli *Client) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error) {
func (cli *Client) ContainerExecCreate(ctx context.Context, container string, options container.ExecOptions) (types.IDResponse, error) {
var response types.IDResponse
// Make sure we negotiated (if the client is configured to do so),
@@ -22,14 +23,14 @@ func (cli *Client) ContainerExecCreate(ctx context.Context, container string, co
return response, err
}
if err := cli.NewVersionError(ctx, "1.25", "env"); len(config.Env) != 0 && err != nil {
if err := cli.NewVersionError(ctx, "1.25", "env"); len(options.Env) != 0 && err != nil {
return response, err
}
if versions.LessThan(cli.ClientVersion(), "1.42") {
config.ConsoleSize = nil
options.ConsoleSize = nil
}
resp, err := cli.post(ctx, "/containers/"+container+"/exec", nil, config, nil)
resp, err := cli.post(ctx, "/containers/"+container+"/exec", nil, options, nil)
defer ensureReaderClosed(resp)
if err != nil {
return response, err
@@ -39,7 +40,7 @@ func (cli *Client) ContainerExecCreate(ctx context.Context, container string, co
}
// ContainerExecStart starts an exec process already created in the docker host.
func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error {
func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config container.ExecStartOptions) error {
if versions.LessThan(cli.ClientVersion(), "1.42") {
config.ConsoleSize = nil
}
@@ -52,7 +53,7 @@ func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config
// It returns a types.HijackedConnection with the hijacked connection
// and the a reader to get output. It's up to the called to close
// the hijacked connection by calling types.HijackedResponse.Close.
func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error) {
func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, config container.ExecAttachOptions) (types.HijackedResponse, error) {
if versions.LessThan(cli.ClientVersion(), "1.42") {
config.ConsoleSize = nil
}
@@ -62,8 +63,8 @@ func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, confi
}
// ContainerExecInspect returns information about a specific exec process on the docker host.
func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error) {
var response types.ContainerExecInspect
func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error) {
var response container.ExecInspect
resp, err := cli.get(ctx, "/exec/"+execID+"/json", nil, nil)
if err != nil {
return response, err

View File

@@ -11,6 +11,7 @@ import (
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/errdefs"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@@ -20,7 +21,7 @@ func TestContainerExecCreateError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
_, err := client.ContainerExecCreate(context.Background(), "container_id", types.ExecConfig{})
_, err := client.ContainerExecCreate(context.Background(), "container_id", container.ExecOptions{})
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
}
@@ -32,7 +33,7 @@ func TestContainerExecCreateConnectionError(t *testing.T) {
client, err := NewClientWithOpts(WithAPIVersionNegotiation(), WithHost("tcp://no-such-host.invalid"))
assert.NilError(t, err)
_, err = client.ContainerExecCreate(context.Background(), "", types.ExecConfig{})
_, err = client.ContainerExecCreate(context.Background(), "", container.ExecOptions{})
assert.Check(t, is.ErrorType(err, IsErrConnectionFailed))
}
@@ -50,7 +51,7 @@ func TestContainerExecCreate(t *testing.T) {
if err := req.ParseForm(); err != nil {
return nil, err
}
execConfig := &types.ExecConfig{}
execConfig := &container.ExecOptions{}
if err := json.NewDecoder(req.Body).Decode(execConfig); err != nil {
return nil, err
}
@@ -70,7 +71,7 @@ func TestContainerExecCreate(t *testing.T) {
}),
}
r, err := client.ContainerExecCreate(context.Background(), "container_id", types.ExecConfig{
r, err := client.ContainerExecCreate(context.Background(), "container_id", container.ExecOptions{
User: "user",
})
if err != nil {
@@ -85,7 +86,7 @@ func TestContainerExecStartError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
err := client.ContainerExecStart(context.Background(), "nothing", types.ExecStartCheck{})
err := client.ContainerExecStart(context.Background(), "nothing", container.ExecStartOptions{})
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
}
@@ -99,12 +100,12 @@ func TestContainerExecStart(t *testing.T) {
if err := req.ParseForm(); err != nil {
return nil, err
}
execStartCheck := &types.ExecStartCheck{}
if err := json.NewDecoder(req.Body).Decode(execStartCheck); err != nil {
options := &container.ExecStartOptions{}
if err := json.NewDecoder(req.Body).Decode(options); err != nil {
return nil, err
}
if execStartCheck.Tty || !execStartCheck.Detach {
return nil, fmt.Errorf("expected execStartCheck{Detach:true,Tty:false}, got %v", execStartCheck)
if options.Tty || !options.Detach {
return nil, fmt.Errorf("expected ExecStartOptions{Detach:true,Tty:false}, got %v", options)
}
return &http.Response{
@@ -114,7 +115,7 @@ func TestContainerExecStart(t *testing.T) {
}),
}
err := client.ContainerExecStart(context.Background(), "exec_id", types.ExecStartCheck{
err := client.ContainerExecStart(context.Background(), "exec_id", container.ExecStartOptions{
Detach: true,
Tty: false,
})
@@ -138,7 +139,7 @@ func TestContainerExecInspect(t *testing.T) {
if !strings.HasPrefix(req.URL.Path, expectedURL) {
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
}
b, err := json.Marshal(types.ContainerExecInspect{
b, err := json.Marshal(container.ExecInspect{
ExecID: "exec_id",
ContainerID: "container_id",
})

View File

@@ -83,55 +83,3 @@ func TestContainerInspect(t *testing.T) {
t.Fatalf("expected `name`, got %s", r.Name)
}
}
// TestContainerInspectNode tests that the "Node" field is included in the "inspect"
// output. This information is only present when connected to a Swarm standalone API.
func TestContainerInspectNode(t *testing.T) {
client := &Client{
client: newMockClient(func(req *http.Request) (*http.Response, error) {
content, err := json.Marshal(types.ContainerJSON{
ContainerJSONBase: &types.ContainerJSONBase{
ID: "container_id",
Image: "image",
Name: "name",
Node: &types.ContainerNode{
ID: "container_node_id",
Addr: "container_node",
Labels: map[string]string{"foo": "bar"},
},
},
})
if err != nil {
return nil, err
}
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewReader(content)),
}, nil
}),
}
r, err := client.ContainerInspect(context.Background(), "container_id")
if err != nil {
t.Fatal(err)
}
if r.ID != "container_id" {
t.Fatalf("expected `container_id`, got %s", r.ID)
}
if r.Image != "image" {
t.Fatalf("expected `image`, got %s", r.Image)
}
if r.Name != "name" {
t.Fatalf("expected `name`, got %s", r.Name)
}
if r.Node.ID != "container_node_id" {
t.Fatalf("expected `container_node_id`, got %s", r.Node.ID)
}
if r.Node.Addr != "container_node" {
t.Fatalf("expected `container_node`, got %s", r.Node.Addr)
}
foo, ok := r.Node.Labels["foo"]
if foo != "bar" || !ok {
t.Fatalf("expected `bar` for label `foo`")
}
}

View File

@@ -5,13 +5,13 @@ import (
"encoding/json"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
)
// ContainersPrune requests the daemon to delete unused data
func (cli *Client) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error) {
var report types.ContainersPruneReport
func (cli *Client) ContainersPrune(ctx context.Context, pruneFilters filters.Args) (container.PruneReport, error) {
var report container.PruneReport
if err := cli.NewVersionError(ctx, "1.25", "container prune"); err != nil {
return report, err

View File

@@ -10,7 +10,7 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/errdefs"
"gotest.tools/v3/assert"
@@ -93,7 +93,7 @@ func TestContainersPrune(t *testing.T) {
actual := query.Get(key)
assert.Check(t, is.Equal(expected, actual))
}
content, err := json.Marshal(types.ContainersPruneReport{
content, err := json.Marshal(container.PruneReport{
ContainersDeleted: []string{"container_id1", "container_id2"},
SpaceReclaimed: 9999,
})

View File

@@ -4,12 +4,12 @@ import (
"context"
"net/url"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
)
// ContainerStats returns near realtime stats for a given container.
// It's up to the caller to close the io.ReadCloser returned.
func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
func (cli *Client) ContainerStats(ctx context.Context, containerID string, stream bool) (container.StatsResponseReader, error) {
query := url.Values{}
query.Set("stream", "0")
if stream {
@@ -18,10 +18,10 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea
resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil)
if err != nil {
return types.ContainerStats{}, err
return container.StatsResponseReader{}, err
}
return types.ContainerStats{
return container.StatsResponseReader{
Body: resp.body,
OSType: getDockerOS(resp.header.Get("Server")),
}, nil
@@ -29,17 +29,17 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea
// ContainerStatsOneShot gets a single stat entry from a container.
// It differs from `ContainerStats` in that the API should not wait to prime the stats
func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string) (types.ContainerStats, error) {
func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string) (container.StatsResponseReader, error) {
query := url.Values{}
query.Set("stream", "0")
query.Set("one-shot", "1")
resp, err := cli.get(ctx, "/containers/"+containerID+"/stats", query, nil)
if err != nil {
return types.ContainerStats{}, err
return container.StatsResponseReader{}, err
}
return types.ContainerStats{
return container.StatsResponseReader{
Body: resp.body,
OSType: getDockerOS(resp.header.Get("Server")),
}, nil

View File

@@ -6,7 +6,6 @@ import (
"net/url"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
timetypes "github.com/docker/docker/api/types/time"
@@ -16,7 +15,7 @@ import (
// by cancelling the context. Once the stream has been completely read an io.EOF error will
// be sent over the error channel. If an error is sent all processing will be stopped. It's up
// to the caller to reopen the stream in the event of an error by reinvoking this method.
func (cli *Client) Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error) {
func (cli *Client) Events(ctx context.Context, options events.ListOptions) (<-chan events.Message, <-chan error) {
messages := make(chan events.Message)
errs := make(chan error, 1)
@@ -68,7 +67,7 @@ func (cli *Client) Events(ctx context.Context, options types.EventsOptions) (<-c
return messages, errs
}
func buildEventsQueryParams(cliVersion string, options types.EventsOptions) (url.Values, error) {
func buildEventsQueryParams(cliVersion string, options events.ListOptions) (url.Values, error) {
query := url.Values{}
ref := time.Now()

View File

@@ -10,7 +10,6 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/errdefs"
@@ -20,17 +19,17 @@ import (
func TestEventsErrorInOptions(t *testing.T) {
errorCases := []struct {
options types.EventsOptions
options events.ListOptions
expectedError string
}{
{
options: types.EventsOptions{
options: events.ListOptions{
Since: "2006-01-02TZ",
},
expectedError: `parsing time "2006-01-02TZ"`,
},
{
options: types.EventsOptions{
options: events.ListOptions{
Until: "2006-01-02TZ",
},
expectedError: `parsing time "2006-01-02TZ"`,
@@ -52,7 +51,7 @@ func TestEventsErrorFromServer(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
_, errs := client.Events(context.Background(), types.EventsOptions{})
_, errs := client.Events(context.Background(), events.ListOptions{})
err := <-errs
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
}
@@ -64,13 +63,13 @@ func TestEvents(t *testing.T) {
expectedFiltersJSON := fmt.Sprintf(`{"type":{"%s":true}}`, events.ContainerEventType)
eventsCases := []struct {
options types.EventsOptions
options events.ListOptions
events []events.Message
expectedEvents map[string]bool
expectedQueryParams map[string]string
}{
{
options: types.EventsOptions{
options: events.ListOptions{
Filters: fltrs,
},
expectedQueryParams: map[string]string{
@@ -80,7 +79,7 @@ func TestEvents(t *testing.T) {
expectedEvents: make(map[string]bool),
},
{
options: types.EventsOptions{
options: events.ListOptions{
Filters: fltrs,
},
expectedQueryParams: map[string]string{

View File

@@ -14,7 +14,6 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/errdefs"
units "github.com/docker/go-units"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@@ -123,7 +122,7 @@ func TestImageBuild(t *testing.T) {
},
{
buildOptions: types.ImageBuildOptions{
Ulimits: []*units.Ulimit{
Ulimits: []*container.Ulimit{
{
Name: "nproc",
Hard: 65557,

Some files were not shown because too many files have changed in this diff Show More