2018-02-05 21:05:59 +00:00
|
|
|
package config // import "github.com/docker/docker/daemon/config"
|
2013-10-05 02:25:15 +00:00
|
|
|
|
|
|
|
import (
|
2015-12-10 23:35:10 +00:00
|
|
|
"bytes"
|
2023-06-23 00:33:17 +00:00
|
|
|
"context"
|
2015-12-10 23:35:10 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2019-11-02 00:09:40 +00:00
|
|
|
"net"
|
2021-08-31 12:05:49 +00:00
|
|
|
"net/url"
|
2017-10-07 21:26:50 +00:00
|
|
|
"os"
|
2015-12-10 23:35:10 +00:00
|
|
|
"strings"
|
|
|
|
|
2023-12-21 17:41:00 +00:00
|
|
|
"dario.cat/mergo"
|
2023-09-13 15:41:45 +00:00
|
|
|
"github.com/containerd/log"
|
daemon: raise default minimum API version to v1.24
The daemon currently provides support for API versions all the way back
to v1.12, which is the version of the API that shipped with docker 1.0. On
Windows, the minimum supported version is v1.24.
Such old versions of the client are rare, and supporting older API versions
has accumulated significant amounts of code to remain backward-compatible
(which is largely untested, and a "best-effort" at most).
This patch updates the minimum API version to v1.24, which is the fallback
API version used when API-version negotiation fails. The intent is to start
deprecating older API versions, but no code is removed yet as part of this
patch, and a DOCKER_MIN_API_VERSION environment variable is added, which
allows overriding the minimum version (to allow restoring the behavior from
before this patch).
With this patch the daemon defaults to API v1.24 as minimum:
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.24)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Trying to use an older version of the API produces an error:
DOCKER_API_VERSION=1.23 docker version
Client:
Version: 24.0.2
API version: 1.23 (downgraded from 1.43)
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Error response from daemon: client version 1.23 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version
To restore the previous minimum, users can start the daemon with the
DOCKER_MIN_API_VERSION environment variable set:
DOCKER_MIN_API_VERSION=1.12 dockerd
API 1.12 is the oldest supported API version on Linux;
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.12)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
When using the `DOCKER_MIN_API_VERSION` with a version of the API that
is not supported, an error is produced when starting the daemon;
DOCKER_MIN_API_VERSION=1.11 dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: 1.11
DOCKER_MIN_API_VERSION=1.45 dockerd --validate
invalid DOCKER_MIN_API_VERSION: maximum supported API version is 1.44: 1.45
Specifying a malformed API version also produces the same error;
DOCKER_MIN_API_VERSION=hello dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: hello
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-12-04 12:44:21 +00:00
|
|
|
"github.com/docker/docker/api"
|
|
|
|
"github.com/docker/docker/api/types/versions"
|
2014-08-10 01:18:32 +00:00
|
|
|
"github.com/docker/docker/opts"
|
2016-03-08 21:03:37 +00:00
|
|
|
"github.com/docker/docker/registry"
|
2018-11-24 13:47:40 +00:00
|
|
|
"github.com/pkg/errors"
|
2016-06-21 20:42:47 +00:00
|
|
|
"github.com/spf13/pflag"
|
daemon: raise default minimum API version to v1.24
The daemon currently provides support for API versions all the way back
to v1.12, which is the version of the API that shipped with docker 1.0. On
Windows, the minimum supported version is v1.24.
Such old versions of the client are rare, and supporting older API versions
has accumulated significant amounts of code to remain backward-compatible
(which is largely untested, and a "best-effort" at most).
This patch updates the minimum API version to v1.24, which is the fallback
API version used when API-version negotiation fails. The intent is to start
deprecating older API versions, but no code is removed yet as part of this
patch, and a DOCKER_MIN_API_VERSION environment variable is added, which
allows overriding the minimum version (to allow restoring the behavior from
before this patch).
With this patch the daemon defaults to API v1.24 as minimum:
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.24)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Trying to use an older version of the API produces an error:
DOCKER_API_VERSION=1.23 docker version
Client:
Version: 24.0.2
API version: 1.23 (downgraded from 1.43)
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Error response from daemon: client version 1.23 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version
To restore the previous minimum, users can start the daemon with the
DOCKER_MIN_API_VERSION environment variable set:
DOCKER_MIN_API_VERSION=1.12 dockerd
API 1.12 is the oldest supported API version on Linux;
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.12)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
When using the `DOCKER_MIN_API_VERSION` with a version of the API that
is not supported, an error is produced when starting the daemon;
DOCKER_MIN_API_VERSION=1.11 dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: 1.11
DOCKER_MIN_API_VERSION=1.45 dockerd --validate
invalid DOCKER_MIN_API_VERSION: maximum supported API version is 1.44: 1.45
Specifying a malformed API version also produces the same error;
DOCKER_MIN_API_VERSION=hello dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: hello
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-12-04 12:44:21 +00:00
|
|
|
"golang.org/x/text/encoding"
|
|
|
|
"golang.org/x/text/encoding/unicode"
|
|
|
|
"golang.org/x/text/transform"
|
2013-10-05 02:25:15 +00:00
|
|
|
)
|
|
|
|
|
2016-05-06 04:45:55 +00:00
|
|
|
const (
|
2017-01-23 11:23:07 +00:00
|
|
|
// DefaultMaxConcurrentDownloads is the default value for
|
2016-05-06 04:45:55 +00:00
|
|
|
// maximum number of downloads that
|
2022-10-28 19:52:57 +00:00
|
|
|
// may take place at a time.
|
2017-01-23 11:23:07 +00:00
|
|
|
DefaultMaxConcurrentDownloads = 3
|
|
|
|
// DefaultMaxConcurrentUploads is the default value for
|
2016-05-06 04:45:55 +00:00
|
|
|
// maximum number of uploads that
|
2022-10-28 19:52:57 +00:00
|
|
|
// may take place at a time.
|
2017-01-23 11:23:07 +00:00
|
|
|
DefaultMaxConcurrentUploads = 5
|
2019-06-25 13:26:36 +00:00
|
|
|
// DefaultDownloadAttempts is the default value for
|
|
|
|
// maximum number of attempts that
|
|
|
|
// may take place at a time for each pull when the connection is lost.
|
|
|
|
DefaultDownloadAttempts = 5
|
2022-02-18 17:07:40 +00:00
|
|
|
// DefaultShmSize is the default value for container's shm size (64 MiB)
|
|
|
|
DefaultShmSize int64 = 64 * 1024 * 1024
|
2017-01-23 11:23:07 +00:00
|
|
|
// DefaultNetworkMtu is the default value for network MTU
|
|
|
|
DefaultNetworkMtu = 1500
|
|
|
|
// DisableNetworkBridge is the default value of the option to disable network bridge
|
|
|
|
DisableNetworkBridge = "none"
|
2022-04-02 16:40:09 +00:00
|
|
|
// DefaultShutdownTimeout is the default shutdown timeout (in seconds) for
|
|
|
|
// the daemon for containers to stop when it is shutting down.
|
|
|
|
DefaultShutdownTimeout = 15
|
2017-04-10 09:25:15 +00:00
|
|
|
// DefaultInitBinary is the name of the default init binary
|
|
|
|
DefaultInitBinary = "docker-init"
|
2020-11-09 15:24:14 +00:00
|
|
|
// DefaultRuntimeBinary is the default runtime to be used by
|
|
|
|
// containerd if none is specified
|
|
|
|
DefaultRuntimeBinary = "runc"
|
2022-04-02 15:43:50 +00:00
|
|
|
// DefaultContainersNamespace is the name of the default containerd namespace used for users containers.
|
|
|
|
DefaultContainersNamespace = "moby"
|
|
|
|
// DefaultPluginNamespace is the name of the default containerd namespace used for plugins.
|
|
|
|
DefaultPluginNamespace = "plugins.moby"
|
daemon: raise default minimum API version to v1.24
The daemon currently provides support for API versions all the way back
to v1.12, which is the version of the API that shipped with docker 1.0. On
Windows, the minimum supported version is v1.24.
Such old versions of the client are rare, and supporting older API versions
has accumulated significant amounts of code to remain backward-compatible
(which is largely untested, and a "best-effort" at most).
This patch updates the minimum API version to v1.24, which is the fallback
API version used when API-version negotiation fails. The intent is to start
deprecating older API versions, but no code is removed yet as part of this
patch, and a DOCKER_MIN_API_VERSION environment variable is added, which
allows overriding the minimum version (to allow restoring the behavior from
before this patch).
With this patch the daemon defaults to API v1.24 as minimum:
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.24)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Trying to use an older version of the API produces an error:
DOCKER_API_VERSION=1.23 docker version
Client:
Version: 24.0.2
API version: 1.23 (downgraded from 1.43)
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Error response from daemon: client version 1.23 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version
To restore the previous minimum, users can start the daemon with the
DOCKER_MIN_API_VERSION environment variable set:
DOCKER_MIN_API_VERSION=1.12 dockerd
API 1.12 is the oldest supported API version on Linux;
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.12)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
When using the `DOCKER_MIN_API_VERSION` with a version of the API that
is not supported, an error is produced when starting the daemon;
DOCKER_MIN_API_VERSION=1.11 dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: 1.11
DOCKER_MIN_API_VERSION=1.45 dockerd --validate
invalid DOCKER_MIN_API_VERSION: maximum supported API version is 1.44: 1.45
Specifying a malformed API version also produces the same error;
DOCKER_MIN_API_VERSION=hello dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: hello
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-12-04 12:44:21 +00:00
|
|
|
// defaultMinAPIVersion is the minimum API version supported by the API.
|
|
|
|
// This version can be overridden through the "DOCKER_MIN_API_VERSION"
|
2024-01-21 23:36:13 +00:00
|
|
|
// environment variable. It currently defaults to the minimum API version
|
|
|
|
// supported by the API server.
|
2024-01-22 15:49:26 +00:00
|
|
|
defaultMinAPIVersion = api.MinSupportedAPIVersion
|
2021-06-07 11:44:32 +00:00
|
|
|
// SeccompProfileDefault is the built-in default seccomp profile.
|
2021-08-07 13:37:03 +00:00
|
|
|
SeccompProfileDefault = "builtin"
|
2021-06-07 11:44:32 +00:00
|
|
|
// SeccompProfileUnconfined is a special profile name for seccomp to use an
|
|
|
|
// "unconfined" seccomp profile.
|
|
|
|
SeccompProfileUnconfined = "unconfined"
|
2016-05-26 21:07:30 +00:00
|
|
|
)
|
|
|
|
|
2016-02-02 19:33:41 +00:00
|
|
|
// flatOptions contains configuration keys
|
|
|
|
// that MUST NOT be parsed as deep structures.
|
|
|
|
// Use this to differentiate these options
|
2022-12-15 09:26:50 +00:00
|
|
|
// with others like the ones in TLSOptions.
|
2016-02-02 19:33:41 +00:00
|
|
|
var flatOptions = map[string]bool{
|
2023-04-03 19:35:21 +00:00
|
|
|
"cluster-store-opts": true,
|
|
|
|
"default-network-opts": true,
|
|
|
|
"log-opts": true,
|
|
|
|
"runtimes": true,
|
|
|
|
"default-ulimits": true,
|
|
|
|
"features": true,
|
|
|
|
"builder": true,
|
2016-02-02 19:33:41 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 01:52:35 +00:00
|
|
|
// skipValidateOptions contains configuration keys
|
|
|
|
// that will be skipped from findConfigurationConflicts
|
|
|
|
// for unknown flag validation.
|
|
|
|
var skipValidateOptions = map[string]bool{
|
|
|
|
"features": true,
|
2018-09-05 02:12:44 +00:00
|
|
|
"builder": true,
|
2019-06-15 04:59:07 +00:00
|
|
|
// Corresponding flag has been removed because it was already unusable
|
|
|
|
"deprecated-key-path": true,
|
2018-08-06 01:52:35 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 22:28:26 +00:00
|
|
|
// skipDuplicates contains configuration keys that
|
|
|
|
// will be skipped when checking duplicated
|
|
|
|
// configuration field defined in both daemon
|
|
|
|
// config file and from dockerd cli flags.
|
|
|
|
// This allows some configurations to be merged
|
|
|
|
// during the parsing.
|
|
|
|
var skipDuplicates = map[string]bool{
|
|
|
|
"runtimes": true,
|
|
|
|
}
|
|
|
|
|
2015-12-10 23:35:10 +00:00
|
|
|
// LogConfig represents the default log configuration.
|
|
|
|
// It includes json tags to deserialize configuration from a file
|
2016-03-28 10:57:55 +00:00
|
|
|
// using the same names that the flags in the command line use.
|
2015-12-10 23:35:10 +00:00
|
|
|
type LogConfig struct {
|
|
|
|
Type string `json:"log-driver,omitempty"`
|
|
|
|
Config map[string]string `json:"log-opts,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-03-28 18:55:20 +00:00
|
|
|
// commonBridgeConfig stores all the platform-common bridge driver specific
|
|
|
|
// configuration.
|
|
|
|
type commonBridgeConfig struct {
|
|
|
|
Iface string `json:"bridge,omitempty"`
|
|
|
|
FixedCIDR string `json:"fixed-cidr,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-12-13 23:04:59 +00:00
|
|
|
// NetworkConfig stores the daemon-wide networking configurations
|
|
|
|
type NetworkConfig struct {
|
|
|
|
// Default address pools for docker networks
|
|
|
|
DefaultAddressPools opts.PoolsOpt `json:"default-address-pools,omitempty"`
|
2018-07-17 19:11:38 +00:00
|
|
|
// NetworkControlPlaneMTU allows to specify the control plane MTU, this will allow to optimize the network use in some components
|
|
|
|
NetworkControlPlaneMTU int `json:"network-control-plane-mtu,omitempty"`
|
2022-01-27 20:13:45 +00:00
|
|
|
// Default options for newly created networks
|
|
|
|
DefaultNetworkOpts map[string]map[string]string `json:"default-network-opts,omitempty"`
|
2016-12-13 23:04:59 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 09:26:50 +00:00
|
|
|
// TLSOptions defines TLS configuration for the daemon server.
|
2015-12-10 23:35:10 +00:00
|
|
|
// It includes json tags to deserialize configuration from a file
|
2016-03-28 10:57:55 +00:00
|
|
|
// using the same names that the flags in the command line use.
|
2022-12-15 09:26:50 +00:00
|
|
|
type TLSOptions struct {
|
2015-12-10 23:35:10 +00:00
|
|
|
CAFile string `json:"tlscacert,omitempty"`
|
|
|
|
CertFile string `json:"tlscert,omitempty"`
|
|
|
|
KeyFile string `json:"tlskey,omitempty"`
|
|
|
|
}
|
|
|
|
|
2019-06-06 01:36:33 +00:00
|
|
|
// DNSConfig defines the DNS configurations.
|
|
|
|
type DNSConfig struct {
|
2023-11-13 11:22:04 +00:00
|
|
|
DNS []net.IP `json:"dns,omitempty"`
|
2019-11-02 00:09:40 +00:00
|
|
|
DNSOptions []string `json:"dns-opts,omitempty"`
|
|
|
|
DNSSearch []string `json:"dns-search,omitempty"`
|
|
|
|
HostGatewayIP net.IP `json:"host-gateway-ip,omitempty"`
|
2019-06-06 01:36:33 +00:00
|
|
|
}
|
|
|
|
|
2016-03-28 10:57:55 +00:00
|
|
|
// CommonConfig defines the configuration of a docker daemon which is
|
2015-04-24 22:36:11 +00:00
|
|
|
// common across platforms.
|
2015-12-10 23:35:10 +00:00
|
|
|
// It includes json tags to deserialize configuration from a file
|
2016-03-28 10:57:55 +00:00
|
|
|
// using the same names that the flags in the command line use.
|
2015-04-24 22:36:11 +00:00
|
|
|
type CommonConfig struct {
|
2023-06-30 08:52:31 +00:00
|
|
|
AuthorizationPlugins []string `json:"authorization-plugins,omitempty"` // AuthorizationPlugins holds list of authorization plugins
|
|
|
|
AutoRestart bool `json:"-"`
|
|
|
|
DisableBridge bool `json:"-"`
|
|
|
|
ExecOptions []string `json:"exec-opts,omitempty"`
|
|
|
|
GraphDriver string `json:"storage-driver,omitempty"`
|
|
|
|
GraphOptions []string `json:"storage-opts,omitempty"`
|
|
|
|
Labels []string `json:"labels,omitempty"`
|
|
|
|
NetworkDiagnosticPort int `json:"network-diagnostic-port,omitempty"`
|
|
|
|
Pidfile string `json:"pidfile,omitempty"`
|
|
|
|
RawLogs bool `json:"raw-logs,omitempty"`
|
|
|
|
Root string `json:"data-root,omitempty"`
|
|
|
|
ExecRoot string `json:"exec-root,omitempty"`
|
|
|
|
SocketGroup string `json:"group,omitempty"`
|
|
|
|
CorsHeaders string `json:"api-cors-header,omitempty"`
|
daemon/config: move proxy settings to "proxies" struct within daemon.json
This is a follow-up to 427c7cc5f86364466c7173e8ca59b97c3876471d, which added
proxy-configuration options ("http-proxy", "https-proxy", "no-proxy") to the
dockerd cli and in `daemon.json`.
While working on documentation changes for this feature, I realised that those
options won't be "next" to each-other when formatting the daemon.json JSON, for
example using `jq` (which sorts the fields alphabetically). As it's possible that
additional proxy configuration options are added in future, I considered that
grouping these options in a struct within the JSON may help setting these options,
as well as discovering related options.
This patch introduces a "proxies" field in the JSON, which includes the
"http-proxy", "https-proxy", "no-proxy" options.
Conflict detection continues to work as before; with this patch applied:
mkdir -p /etc/docker/
echo '{"proxies":{"http-proxy":"http-config", "https-proxy":"https-config", "no-proxy": "no-proxy-config"}}' > /etc/docker/daemon.json
dockerd --http-proxy=http-flag --https-proxy=https-flag --no-proxy=no-proxy-flag --validate
unable to configure the Docker daemon with file /etc/docker/daemon.json:
the following directives are specified both as a flag and in the configuration file:
http-proxy: (from flag: http-flag, from file: http-config),
https-proxy: (from flag: https-flag, from file: https-config),
no-proxy: (from flag: no-proxy-flag, from file: no-proxy-config)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-02 14:03:39 +00:00
|
|
|
|
|
|
|
// Proxies holds the proxies that are configured for the daemon.
|
|
|
|
Proxies `json:"proxies"`
|
2016-07-27 15:30:15 +00:00
|
|
|
|
|
|
|
// LiveRestoreEnabled determines whether we should keep containers
|
|
|
|
// alive upon daemon shutdown/start
|
|
|
|
LiveRestoreEnabled bool `json:"live-restore,omitempty"`
|
2015-09-10 23:12:00 +00:00
|
|
|
|
2016-05-06 04:45:55 +00:00
|
|
|
// MaxConcurrentDownloads is the maximum number of downloads that
|
|
|
|
// may take place at a time for each pull.
|
2022-04-24 20:59:54 +00:00
|
|
|
MaxConcurrentDownloads int `json:"max-concurrent-downloads,omitempty"`
|
2016-05-06 04:45:55 +00:00
|
|
|
|
|
|
|
// MaxConcurrentUploads is the maximum number of uploads that
|
|
|
|
// may take place at a time for each push.
|
2022-04-24 20:59:54 +00:00
|
|
|
MaxConcurrentUploads int `json:"max-concurrent-uploads,omitempty"`
|
2016-05-06 04:45:55 +00:00
|
|
|
|
2019-06-25 13:26:36 +00:00
|
|
|
// MaxDownloadAttempts is the maximum number of attempts that
|
|
|
|
// may take place at a time for each push.
|
2022-04-24 20:59:54 +00:00
|
|
|
MaxDownloadAttempts int `json:"max-download-attempts,omitempty"`
|
2019-06-25 13:26:36 +00:00
|
|
|
|
2016-05-26 21:07:30 +00:00
|
|
|
// ShutdownTimeout is the timeout value (in seconds) the daemon will wait for the container
|
|
|
|
// to stop when daemon is being shutdown
|
|
|
|
ShutdownTimeout int `json:"shutdown-timeout,omitempty"`
|
|
|
|
|
2023-08-30 20:11:24 +00:00
|
|
|
Debug bool `json:"debug,omitempty"`
|
|
|
|
Hosts []string `json:"hosts,omitempty"`
|
|
|
|
LogLevel string `json:"log-level,omitempty"`
|
|
|
|
LogFormat log.OutputFormat `json:"log-format,omitempty"`
|
|
|
|
TLS *bool `json:"tls,omitempty"`
|
|
|
|
TLSVerify *bool `json:"tlsverify,omitempty"`
|
2016-01-22 18:14:48 +00:00
|
|
|
|
|
|
|
// Embedded structs that allow config
|
|
|
|
// deserialization without the full struct.
|
2022-12-15 09:26:50 +00:00
|
|
|
TLSOptions
|
2016-07-01 01:07:35 +00:00
|
|
|
|
|
|
|
// SwarmDefaultAdvertiseAddr is the default host/IP or network interface
|
|
|
|
// to use if a wildcard address is specified in the ListenAddr value
|
|
|
|
// given to the /swarm/init endpoint and no advertise address is
|
|
|
|
// specified.
|
|
|
|
SwarmDefaultAdvertiseAddr string `json:"swarm-default-advertise-addr"`
|
2018-03-28 23:54:43 +00:00
|
|
|
|
|
|
|
// SwarmRaftHeartbeatTick is the number of ticks in time for swarm mode raft quorum heartbeat
|
|
|
|
// Typical value is 1
|
|
|
|
SwarmRaftHeartbeatTick uint32 `json:"swarm-raft-heartbeat-tick"`
|
|
|
|
|
|
|
|
// SwarmRaftElectionTick is the number of ticks to elapse before followers in the quorum can propose
|
|
|
|
// a new round of leader election. Default, recommended value is at least 10X that of Heartbeat tick.
|
|
|
|
// Higher values can make the quorum less sensitive to transient faults in the environment, but this also
|
|
|
|
// means it takes longer for the managers to detect a down leader.
|
|
|
|
SwarmRaftElectionTick uint32 `json:"swarm-raft-election-tick"`
|
|
|
|
|
|
|
|
MetricsAddress string `json:"metrics-addr"`
|
2016-07-01 01:07:35 +00:00
|
|
|
|
2019-06-06 01:36:33 +00:00
|
|
|
DNSConfig
|
2016-01-22 18:14:48 +00:00
|
|
|
LogConfig
|
2022-10-05 14:28:35 +00:00
|
|
|
BridgeConfig // BridgeConfig holds bridge network specific configuration.
|
2016-12-13 23:04:59 +00:00
|
|
|
NetworkConfig
|
2016-03-08 21:03:37 +00:00
|
|
|
registry.ServiceOptions
|
2015-12-10 23:35:10 +00:00
|
|
|
|
2017-01-23 11:23:07 +00:00
|
|
|
// FIXME(vdemeester) This part is not that clear and is mainly dependent on cli flags
|
|
|
|
// It should probably be handled outside this package.
|
Log active configuration when reloading
When succesfully reloading the daemon configuration, print a message
in the logs with the active configuration:
INFO[2018-01-15T15:36:20.901688317Z] Got signal to reload configuration, reloading from: /etc/docker/daemon.json
INFO[2018-01-14T02:23:48.782769942Z] Reloaded configuration: {"mtu":1500,"pidfile":"/var/run/docker.pid","data-root":"/var/lib/docker","exec-root":"/var/run/docker","group":"docker","deprecated-key-path":"/etc/docker/key.json","max-concurrent-downloads":3,"max-concurrent-uploads":5,"shutdown-timeout":15,"debug":true,"hosts":["unix:///var/run/docker.sock"],"log-level":"info","swarm-default-advertise-addr":"","metrics-addr":"","log-driver":"json-file","ip":"0.0.0.0","icc":true,"iptables":true,"ip-forward":true,"ip-masq":true,"userland-proxy":true,"disable-legacy-registry":true,"experimental":false,"network-control-plane-mtu":1500,"runtimes":{"runc":{"path":"docker-runc"}},"default-runtime":"runc","oom-score-adjust":-500,"default-shm-size":67108864,"default-ipc-mode":"shareable"}
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-01-15 16:11:05 +00:00
|
|
|
ValuesSet map[string]interface{} `json:"-"`
|
2016-10-06 14:09:54 +00:00
|
|
|
|
|
|
|
Experimental bool `json:"experimental"` // Experimental indicates whether experimental features should be exposed or not
|
2017-05-31 00:02:11 +00:00
|
|
|
|
|
|
|
// Exposed node Generic Resources
|
2017-10-29 19:30:31 +00:00
|
|
|
// e.g: ["orange=red", "orange=green", "orange=blue", "apple=3"]
|
|
|
|
NodeGenericResources []string `json:"node-generic-resources,omitempty"`
|
2017-09-22 13:52:41 +00:00
|
|
|
|
|
|
|
// ContainerAddr is the address used to connect to containerd if we're
|
|
|
|
// not starting it ourselves
|
|
|
|
ContainerdAddr string `json:"containerd,omitempty"`
|
2018-06-19 22:53:40 +00:00
|
|
|
|
|
|
|
// CriContainerd determines whether a supervised containerd instance
|
|
|
|
// should be configured with the CRI plugin enabled. This allows using
|
|
|
|
// Docker's containerd instance directly with a Kubernetes kubelet.
|
|
|
|
CriContainerd bool `json:"cri-containerd,omitempty"`
|
2018-08-06 01:52:35 +00:00
|
|
|
|
|
|
|
// Features contains a list of feature key value pairs indicating what features are enabled or disabled.
|
|
|
|
// If a certain feature doesn't appear in this list then it's unset (i.e. neither true nor false).
|
|
|
|
Features map[string]bool `json:"features,omitempty"`
|
2018-09-05 02:12:44 +00:00
|
|
|
|
|
|
|
Builder BuilderConfig `json:"builder,omitempty"`
|
2019-07-11 23:42:16 +00:00
|
|
|
|
|
|
|
ContainerdNamespace string `json:"containerd-namespace,omitempty"`
|
|
|
|
ContainerdPluginNamespace string `json:"containerd-plugin-namespace,omitempty"`
|
2021-02-26 23:23:55 +00:00
|
|
|
|
|
|
|
DefaultRuntime string `json:"default-runtime,omitempty"`
|
2023-03-09 14:18:40 +00:00
|
|
|
|
|
|
|
// CDISpecDirs is a list of directories in which CDI specifications can be found.
|
|
|
|
CDISpecDirs []string `json:"cdi-spec-dirs,omitempty"`
|
daemon: raise default minimum API version to v1.24
The daemon currently provides support for API versions all the way back
to v1.12, which is the version of the API that shipped with docker 1.0. On
Windows, the minimum supported version is v1.24.
Such old versions of the client are rare, and supporting older API versions
has accumulated significant amounts of code to remain backward-compatible
(which is largely untested, and a "best-effort" at most).
This patch updates the minimum API version to v1.24, which is the fallback
API version used when API-version negotiation fails. The intent is to start
deprecating older API versions, but no code is removed yet as part of this
patch, and a DOCKER_MIN_API_VERSION environment variable is added, which
allows overriding the minimum version (to allow restoring the behavior from
before this patch).
With this patch the daemon defaults to API v1.24 as minimum:
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.24)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Trying to use an older version of the API produces an error:
DOCKER_API_VERSION=1.23 docker version
Client:
Version: 24.0.2
API version: 1.23 (downgraded from 1.43)
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Error response from daemon: client version 1.23 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version
To restore the previous minimum, users can start the daemon with the
DOCKER_MIN_API_VERSION environment variable set:
DOCKER_MIN_API_VERSION=1.12 dockerd
API 1.12 is the oldest supported API version on Linux;
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.12)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
When using the `DOCKER_MIN_API_VERSION` with a version of the API that
is not supported, an error is produced when starting the daemon;
DOCKER_MIN_API_VERSION=1.11 dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: 1.11
DOCKER_MIN_API_VERSION=1.45 dockerd --validate
invalid DOCKER_MIN_API_VERSION: maximum supported API version is 1.44: 1.45
Specifying a malformed API version also produces the same error;
DOCKER_MIN_API_VERSION=hello dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: hello
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-12-04 12:44:21 +00:00
|
|
|
|
|
|
|
// The minimum API version provided by the daemon. Defaults to [defaultMinAPIVersion].
|
|
|
|
//
|
|
|
|
// The DOCKER_MIN_API_VERSION allows overriding the minimum API version within
|
|
|
|
// constraints of the minimum and maximum (current) supported API versions.
|
|
|
|
//
|
|
|
|
// API versions older than [defaultMinAPIVersion] are deprecated and
|
|
|
|
// to be removed in a future release. The "DOCKER_MIN_API_VERSION" env
|
|
|
|
// var should only be used for exceptional cases, and the MinAPIVersion
|
|
|
|
// field is therefore not included in the JSON representation.
|
|
|
|
MinAPIVersion string `json:"-"`
|
2013-10-05 02:25:15 +00:00
|
|
|
}
|
2013-10-21 16:04:42 +00:00
|
|
|
|
daemon/config: move proxy settings to "proxies" struct within daemon.json
This is a follow-up to 427c7cc5f86364466c7173e8ca59b97c3876471d, which added
proxy-configuration options ("http-proxy", "https-proxy", "no-proxy") to the
dockerd cli and in `daemon.json`.
While working on documentation changes for this feature, I realised that those
options won't be "next" to each-other when formatting the daemon.json JSON, for
example using `jq` (which sorts the fields alphabetically). As it's possible that
additional proxy configuration options are added in future, I considered that
grouping these options in a struct within the JSON may help setting these options,
as well as discovering related options.
This patch introduces a "proxies" field in the JSON, which includes the
"http-proxy", "https-proxy", "no-proxy" options.
Conflict detection continues to work as before; with this patch applied:
mkdir -p /etc/docker/
echo '{"proxies":{"http-proxy":"http-config", "https-proxy":"https-config", "no-proxy": "no-proxy-config"}}' > /etc/docker/daemon.json
dockerd --http-proxy=http-flag --https-proxy=https-flag --no-proxy=no-proxy-flag --validate
unable to configure the Docker daemon with file /etc/docker/daemon.json:
the following directives are specified both as a flag and in the configuration file:
http-proxy: (from flag: http-flag, from file: http-config),
https-proxy: (from flag: https-flag, from file: https-config),
no-proxy: (from flag: no-proxy-flag, from file: no-proxy-config)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-02 14:03:39 +00:00
|
|
|
// Proxies holds the proxies that are configured for the daemon.
|
|
|
|
type Proxies struct {
|
2021-07-16 07:33:00 +00:00
|
|
|
HTTPProxy string `json:"http-proxy,omitempty"`
|
|
|
|
HTTPSProxy string `json:"https-proxy,omitempty"`
|
|
|
|
NoProxy string `json:"no-proxy,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:16:07 +00:00
|
|
|
// IsValueSet returns true if a configuration value
|
|
|
|
// was explicitly set in the configuration file.
|
2017-01-23 11:23:07 +00:00
|
|
|
func (conf *Config) IsValueSet(name string) bool {
|
|
|
|
if conf.ValuesSet == nil {
|
2016-01-19 19:16:07 +00:00
|
|
|
return false
|
|
|
|
}
|
2017-01-23 11:23:07 +00:00
|
|
|
_, ok := conf.ValuesSet[name]
|
2016-01-19 19:16:07 +00:00
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:11:08 +00:00
|
|
|
// New returns a new fully initialized Config struct with default values set.
|
|
|
|
func New() (*Config, error) {
|
|
|
|
// platform-agnostic default values for the Config.
|
|
|
|
cfg := &Config{
|
2021-07-10 12:55:23 +00:00
|
|
|
CommonConfig: CommonConfig{
|
2022-06-06 17:38:32 +00:00
|
|
|
ShutdownTimeout: DefaultShutdownTimeout,
|
2021-07-10 12:55:23 +00:00
|
|
|
LogConfig: LogConfig{
|
|
|
|
Config: make(map[string]string),
|
|
|
|
},
|
2022-06-06 17:38:32 +00:00
|
|
|
MaxConcurrentDownloads: DefaultMaxConcurrentDownloads,
|
|
|
|
MaxConcurrentUploads: DefaultMaxConcurrentUploads,
|
|
|
|
MaxDownloadAttempts: DefaultDownloadAttempts,
|
2023-11-03 10:08:22 +00:00
|
|
|
BridgeConfig: BridgeConfig{
|
|
|
|
DefaultBridgeConfig: DefaultBridgeConfig{
|
|
|
|
MTU: DefaultNetworkMtu,
|
|
|
|
},
|
|
|
|
},
|
2022-06-06 17:38:32 +00:00
|
|
|
NetworkConfig: NetworkConfig{
|
|
|
|
NetworkControlPlaneMTU: DefaultNetworkMtu,
|
2022-01-27 20:13:45 +00:00
|
|
|
DefaultNetworkOpts: make(map[string]map[string]string),
|
2022-06-06 17:38:32 +00:00
|
|
|
},
|
|
|
|
ContainerdNamespace: DefaultContainersNamespace,
|
|
|
|
ContainerdPluginNamespace: DefaultPluginNamespace,
|
|
|
|
DefaultRuntime: StockRuntimeName,
|
daemon: raise default minimum API version to v1.24
The daemon currently provides support for API versions all the way back
to v1.12, which is the version of the API that shipped with docker 1.0. On
Windows, the minimum supported version is v1.24.
Such old versions of the client are rare, and supporting older API versions
has accumulated significant amounts of code to remain backward-compatible
(which is largely untested, and a "best-effort" at most).
This patch updates the minimum API version to v1.24, which is the fallback
API version used when API-version negotiation fails. The intent is to start
deprecating older API versions, but no code is removed yet as part of this
patch, and a DOCKER_MIN_API_VERSION environment variable is added, which
allows overriding the minimum version (to allow restoring the behavior from
before this patch).
With this patch the daemon defaults to API v1.24 as minimum:
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.24)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Trying to use an older version of the API produces an error:
DOCKER_API_VERSION=1.23 docker version
Client:
Version: 24.0.2
API version: 1.23 (downgraded from 1.43)
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Error response from daemon: client version 1.23 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version
To restore the previous minimum, users can start the daemon with the
DOCKER_MIN_API_VERSION environment variable set:
DOCKER_MIN_API_VERSION=1.12 dockerd
API 1.12 is the oldest supported API version on Linux;
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.12)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
When using the `DOCKER_MIN_API_VERSION` with a version of the API that
is not supported, an error is produced when starting the daemon;
DOCKER_MIN_API_VERSION=1.11 dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: 1.11
DOCKER_MIN_API_VERSION=1.45 dockerd --validate
invalid DOCKER_MIN_API_VERSION: maximum supported API version is 1.44: 1.45
Specifying a malformed API version also produces the same error;
DOCKER_MIN_API_VERSION=hello dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: hello
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-12-04 12:44:21 +00:00
|
|
|
MinAPIVersion: defaultMinAPIVersion,
|
2021-07-10 12:55:23 +00:00
|
|
|
},
|
|
|
|
}
|
2022-06-06 19:11:08 +00:00
|
|
|
|
|
|
|
if err := setPlatformDefaults(cfg); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfg, nil
|
2016-06-21 20:42:47 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 12:48:25 +00:00
|
|
|
// GetConflictFreeLabels validates Labels for conflict
|
2016-07-12 12:08:05 +00:00
|
|
|
// In swarm the duplicates for labels are removed
|
|
|
|
// so we only take same values here, no conflict values
|
|
|
|
// If the key-value is the same we will only take the last label
|
|
|
|
func GetConflictFreeLabels(labels []string) ([]string, error) {
|
|
|
|
labelMap := map[string]string{}
|
|
|
|
for _, label := range labels {
|
2022-10-31 14:00:03 +00:00
|
|
|
key, val, ok := strings.Cut(label, "=")
|
|
|
|
if ok {
|
2016-07-12 12:08:05 +00:00
|
|
|
// If there is a conflict we will return an error
|
2022-10-31 14:00:03 +00:00
|
|
|
if v, ok := labelMap[key]; ok && v != val {
|
|
|
|
return nil, errors.Errorf("conflict labels for %s=%s and %s=%s", key, val, key, v)
|
2016-07-12 12:08:05 +00:00
|
|
|
}
|
2022-10-31 14:00:03 +00:00
|
|
|
labelMap[key] = val
|
2016-07-12 12:08:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newLabels := []string{}
|
|
|
|
for k, v := range labelMap {
|
2022-10-05 14:28:35 +00:00
|
|
|
newLabels = append(newLabels, k+"="+v)
|
2016-07-12 12:08:05 +00:00
|
|
|
}
|
|
|
|
return newLabels, nil
|
|
|
|
}
|
|
|
|
|
2017-01-23 11:23:07 +00:00
|
|
|
// Reload reads the configuration in the host and reloads the daemon and server.
|
|
|
|
func Reload(configFile string, flags *pflag.FlagSet, reload func(*Config)) error {
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(context.TODO()).Infof("Got signal to reload configuration, reloading from: %s", configFile)
|
2015-12-10 23:35:10 +00:00
|
|
|
newConfig, err := getConflictFreeConfiguration(configFile, flags)
|
|
|
|
if err != nil {
|
2017-10-07 21:26:50 +00:00
|
|
|
if flags.Changed("config-file") || !os.IsNotExist(err) {
|
2018-11-24 13:47:40 +00:00
|
|
|
return errors.Wrapf(err, "unable to configure the Docker daemon with file %s", configFile)
|
2017-10-07 21:26:50 +00:00
|
|
|
}
|
2022-06-06 19:11:08 +00:00
|
|
|
newConfig, err = New()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-12-10 23:35:10 +00:00
|
|
|
}
|
2016-03-11 08:50:49 +00:00
|
|
|
|
2017-11-12 02:09:28 +00:00
|
|
|
// Check if duplicate label-keys with different values are found
|
|
|
|
newLabels, err := GetConflictFreeLabels(newConfig.Labels)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-07-12 12:08:05 +00:00
|
|
|
}
|
2017-11-12 02:09:28 +00:00
|
|
|
newConfig.Labels = newLabels
|
2016-07-12 12:08:05 +00:00
|
|
|
|
daemon/config: Reload(): add TODO for config reload logic
The Reload logic is problematic and needs a rewrite.
Currently, config.Reload() is validating newConfig before the reload callback
is executed. At that point, newConfig may be a partial configuration, yet to be
merged with the existing configuration (in the "reload()" callback). Validating
this config before it's merged can result in incorrect validation errors.
However, the current "reload()" callback we use is DaemonCli.reloadConfig(),
which includes a call to Daemon.Reload(), which both performs "merging" and
validation, as well as actually updating the daemon configuration. Calling
DaemonCli.reloadConfig() *before* validation, could thus lead to a failure in
that function (making the reload non-atomic).
While *some* errors could always occur when applying/updating the config, we
should make it more atomic, and;
1. get (a copy of) the active configuration
2. get the new configuration
3. apply the (reloadable) options from the new configuration
4. validate the merged results
5. apply the new configuration.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-24 14:18:20 +00:00
|
|
|
// TODO(thaJeztah) This logic is problematic and needs a rewrite;
|
|
|
|
// This is validating newConfig before the "reload()" callback is executed.
|
|
|
|
// At this point, newConfig may be a partial configuration, to be merged
|
|
|
|
// with the existing configuration in the "reload()" callback. Validating
|
|
|
|
// this config before it's merged can result in incorrect validation errors.
|
|
|
|
//
|
|
|
|
// However, the current "reload()" callback we use is DaemonCli.reloadConfig(),
|
|
|
|
// which includes a call to Daemon.Reload(), which both performs "merging"
|
|
|
|
// and validation, as well as actually updating the daemon configuration.
|
|
|
|
// Calling DaemonCli.reloadConfig() *before* validation, could thus lead to
|
|
|
|
// a failure in that function (making the reload non-atomic).
|
|
|
|
//
|
|
|
|
// While *some* errors could always occur when applying/updating the config,
|
|
|
|
// we should make it more atomic, and;
|
|
|
|
//
|
|
|
|
// 1. get (a copy of) the active configuration
|
|
|
|
// 2. get the new configuration
|
|
|
|
// 3. apply the (reloadable) options from the new configuration
|
|
|
|
// 4. validate the merged results
|
|
|
|
// 5. apply the new configuration.
|
2022-04-24 14:14:44 +00:00
|
|
|
if err := Validate(newConfig); err != nil {
|
|
|
|
return errors.Wrap(err, "file configuration validation failed")
|
|
|
|
}
|
|
|
|
|
2016-02-18 21:55:03 +00:00
|
|
|
reload(newConfig)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// boolValue is an interface that boolean value flags implement
|
|
|
|
// to tell the command line how to make -name equivalent to -name=true.
|
|
|
|
type boolValue interface {
|
|
|
|
IsBoolFlag() bool
|
2015-12-10 23:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MergeDaemonConfigurations reads a configuration file,
|
|
|
|
// loads the file configuration in an isolated structure,
|
|
|
|
// and merges the configuration provided from flags on top
|
|
|
|
// if there are no conflicts.
|
2016-06-21 20:42:47 +00:00
|
|
|
func MergeDaemonConfigurations(flagsConfig *Config, flags *pflag.FlagSet, configFile string) (*Config, error) {
|
2015-12-10 23:35:10 +00:00
|
|
|
fileConfig, err := getConflictFreeConfiguration(configFile, flags)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge flags configuration on top of the file configuration
|
|
|
|
if err := mergo.Merge(fileConfig, flagsConfig); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-04-24 20:26:09 +00:00
|
|
|
// validate the merged fileConfig and flagsConfig
|
2017-01-23 11:23:07 +00:00
|
|
|
if err := Validate(fileConfig); err != nil {
|
2018-11-24 13:47:40 +00:00
|
|
|
return nil, errors.Wrap(err, "merged configuration validation from file and command line flags failed")
|
2016-05-23 21:49:50 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 23:35:10 +00:00
|
|
|
return fileConfig, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// getConflictFreeConfiguration loads the configuration from a JSON file.
|
|
|
|
// It compares that configuration with the one provided by the flags,
|
|
|
|
// and returns an error if there are conflicts.
|
2016-06-21 20:42:47 +00:00
|
|
|
func getConflictFreeConfiguration(configFile string, flags *pflag.FlagSet) (*Config, error) {
|
2021-08-24 10:10:50 +00:00
|
|
|
b, err := os.ReadFile(configFile)
|
2015-12-10 23:35:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-01-10 20:35:46 +00:00
|
|
|
// Decode the contents of the JSON file using a [byte order mark] if present, instead of assuming UTF-8 without BOM.
|
|
|
|
// The BOM, if present, will be used to determine the encoding. If no BOM is present, we will assume the default
|
|
|
|
// and preferred encoding for JSON as defined by [RFC 8259], UTF-8 without BOM.
|
|
|
|
//
|
|
|
|
// While JSON is normatively UTF-8 with no BOM, there are a couple of reasons to decode here:
|
|
|
|
// * UTF-8 with BOM is something that new implementations should avoid producing; however, [RFC 8259 Section 8.1]
|
|
|
|
// allows implementations to ignore the UTF-8 BOM when present for interoperability. Older versions of Notepad,
|
|
|
|
// the only text editor available out of the box on Windows Server, writes UTF-8 with a BOM by default.
|
|
|
|
// * The default encoding for [Windows PowerShell] is UTF-16 LE with BOM. While encodings in PowerShell can be a
|
|
|
|
// bit idiosyncratic, BOMs are still generally written. There is no support for selecting UTF-8 without a BOM as
|
|
|
|
// the encoding in Windows PowerShell, though some Cmdlets only write UTF-8 with no BOM. PowerShell Core
|
|
|
|
// introduces `utf8NoBOM` and makes it the default, but PowerShell Core is unlikely to be the implementation for
|
|
|
|
// a majority of Windows Server + PowerShell users.
|
|
|
|
// * While [RFC 8259 Section 8.1] asserts that software that is not part of a closed ecosystem or that crosses a
|
|
|
|
// network boundary should only support UTF-8, and should never write a BOM, it does acknowledge older versions
|
|
|
|
// of the standard, such as [RFC 7159 Section 8.1]. In the interest of pragmatism and easing pain for Windows
|
|
|
|
// users, we consider Windows tools such as Windows PowerShell and Notepad part of our ecosystem, and support
|
|
|
|
// the two most common encodings: UTF-16 LE with BOM, and UTF-8 with BOM, in addition to the standard UTF-8
|
|
|
|
// without BOM.
|
|
|
|
//
|
|
|
|
// [byte order mark]: https://www.unicode.org/faq/utf_bom.html#BOM
|
|
|
|
// [RFC 8259]: https://www.rfc-editor.org/rfc/rfc8259
|
|
|
|
// [RFC 8259 Section 8.1]: https://www.rfc-editor.org/rfc/rfc8259#section-8.1
|
|
|
|
// [RFC 7159 Section 8.1]: https://www.rfc-editor.org/rfc/rfc7159#section-8.1
|
|
|
|
// [Windows PowerShell]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_character_encoding?view=powershell-5.1
|
2023-01-10 23:32:31 +00:00
|
|
|
b, n, err := transform.Bytes(transform.Chain(unicode.BOMOverride(transform.Nop), encoding.UTF8Validator), b)
|
2023-01-10 20:35:46 +00:00
|
|
|
if err != nil {
|
2023-01-10 23:32:31 +00:00
|
|
|
return nil, errors.Wrapf(err, "failed to decode configuration JSON at offset %d", n)
|
2023-01-10 20:35:46 +00:00
|
|
|
}
|
2023-01-09 17:12:07 +00:00
|
|
|
// Trim whitespace so that an empty config can be detected for an early return.
|
2018-11-05 00:52:26 +00:00
|
|
|
b = bytes.TrimSpace(b)
|
2023-01-09 17:12:07 +00:00
|
|
|
|
|
|
|
var config Config
|
2018-11-05 00:52:26 +00:00
|
|
|
if len(b) == 0 {
|
2023-01-09 16:32:36 +00:00
|
|
|
return &config, nil // early return on empty config
|
2018-11-05 00:52:26 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 23:35:10 +00:00
|
|
|
if flags != nil {
|
|
|
|
var jsonConfig map[string]interface{}
|
2018-11-05 00:52:26 +00:00
|
|
|
if err := json.Unmarshal(b, &jsonConfig); err != nil {
|
2015-12-10 23:35:10 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-01-19 19:16:07 +00:00
|
|
|
configSet := configValuesSet(jsonConfig)
|
|
|
|
|
|
|
|
if err := findConfigurationConflicts(configSet, flags); err != nil {
|
2015-12-10 23:35:10 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2016-01-19 19:16:07 +00:00
|
|
|
|
2016-02-18 21:55:03 +00:00
|
|
|
// Override flag values to make sure the values set in the config file with nullable values, like `false`,
|
2016-07-03 17:58:11 +00:00
|
|
|
// are not overridden by default truthy values from the flags that were not explicitly set.
|
2016-02-18 21:55:03 +00:00
|
|
|
// See https://github.com/docker/docker/issues/20289 for an example.
|
|
|
|
//
|
|
|
|
// TODO: Rewrite configuration logic to avoid same issue with other nullable values, like numbers.
|
|
|
|
namedOptions := make(map[string]interface{})
|
|
|
|
for key, value := range configSet {
|
2016-06-22 22:36:51 +00:00
|
|
|
f := flags.Lookup(key)
|
2016-02-18 21:55:03 +00:00
|
|
|
if f == nil { // ignore named flags that don't match
|
|
|
|
namedOptions[key] = value
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := f.Value.(boolValue); ok {
|
|
|
|
f.Value.Set(fmt.Sprintf("%v", value))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(namedOptions) > 0 {
|
|
|
|
// set also default for mergeVal flags that are boolValue at the same time.
|
2016-06-21 20:42:47 +00:00
|
|
|
flags.VisitAll(func(f *pflag.Flag) {
|
2016-02-18 21:55:03 +00:00
|
|
|
if opt, named := f.Value.(opts.NamedOption); named {
|
|
|
|
v, set := namedOptions[opt.Name()]
|
|
|
|
_, boolean := f.Value.(boolValue)
|
|
|
|
if set && boolean {
|
|
|
|
f.Value.Set(fmt.Sprintf("%v", v))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-01-23 11:23:07 +00:00
|
|
|
config.ValuesSet = configSet
|
2015-12-10 23:35:10 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 00:52:26 +00:00
|
|
|
if err := json.Unmarshal(b, &config); err != nil {
|
2016-11-22 06:17:24 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &config, nil
|
2015-12-10 23:35:10 +00:00
|
|
|
}
|
|
|
|
|
2016-01-19 19:16:07 +00:00
|
|
|
// configValuesSet returns the configuration values explicitly set in the file.
|
|
|
|
func configValuesSet(config map[string]interface{}) map[string]interface{} {
|
2015-12-10 23:35:10 +00:00
|
|
|
flatten := make(map[string]interface{})
|
|
|
|
for k, v := range config {
|
2016-02-02 19:33:41 +00:00
|
|
|
if m, isMap := v.(map[string]interface{}); isMap && !flatOptions[k] {
|
2015-12-10 23:35:10 +00:00
|
|
|
for km, vm := range m {
|
|
|
|
flatten[km] = vm
|
|
|
|
}
|
2016-02-02 19:33:41 +00:00
|
|
|
continue
|
2015-12-10 23:35:10 +00:00
|
|
|
}
|
2016-02-02 19:33:41 +00:00
|
|
|
|
|
|
|
flatten[k] = v
|
2015-12-10 23:35:10 +00:00
|
|
|
}
|
2016-01-19 19:16:07 +00:00
|
|
|
return flatten
|
|
|
|
}
|
|
|
|
|
|
|
|
// findConfigurationConflicts iterates over the provided flags searching for
|
2016-01-20 22:16:49 +00:00
|
|
|
// duplicated configurations and unknown keys. It returns an error with all the conflicts if
|
2016-01-19 19:16:07 +00:00
|
|
|
// it finds any.
|
2016-06-21 20:42:47 +00:00
|
|
|
func findConfigurationConflicts(config map[string]interface{}, flags *pflag.FlagSet) error {
|
2016-01-20 22:16:49 +00:00
|
|
|
// 1. Search keys from the file that we don't recognize as flags.
|
|
|
|
unknownKeys := make(map[string]interface{})
|
|
|
|
for key, value := range config {
|
2018-08-06 01:52:35 +00:00
|
|
|
if flag := flags.Lookup(key); flag == nil && !skipValidateOptions[key] {
|
2016-01-20 22:16:49 +00:00
|
|
|
unknownKeys[key] = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-22 18:14:48 +00:00
|
|
|
// 2. Discard values that implement NamedOption.
|
|
|
|
// Their configuration name differs from their flag name, like `labels` and `label`.
|
2016-02-18 21:55:03 +00:00
|
|
|
if len(unknownKeys) > 0 {
|
2016-06-21 20:42:47 +00:00
|
|
|
unknownNamedConflicts := func(f *pflag.Flag) {
|
2016-02-18 21:55:03 +00:00
|
|
|
if namedOption, ok := f.Value.(opts.NamedOption); ok {
|
2019-10-13 20:10:24 +00:00
|
|
|
delete(unknownKeys, namedOption.Name())
|
2016-01-20 22:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-18 21:55:03 +00:00
|
|
|
flags.VisitAll(unknownNamedConflicts)
|
2016-01-20 22:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(unknownKeys) > 0 {
|
|
|
|
var unknown []string
|
|
|
|
for key := range unknownKeys {
|
|
|
|
unknown = append(unknown, key)
|
|
|
|
}
|
2022-10-05 14:28:35 +00:00
|
|
|
return errors.Errorf("the following directives don't match any configuration option: %s", strings.Join(unknown, ", "))
|
2016-01-20 22:16:49 +00:00
|
|
|
}
|
2015-12-10 23:35:10 +00:00
|
|
|
|
2016-01-20 22:16:49 +00:00
|
|
|
var conflicts []string
|
2015-12-10 23:35:10 +00:00
|
|
|
printConflict := func(name string, flagValue, fileValue interface{}) string {
|
2021-08-31 12:13:30 +00:00
|
|
|
switch name {
|
|
|
|
case "http-proxy", "https-proxy":
|
|
|
|
flagValue = MaskCredentials(flagValue.(string))
|
|
|
|
fileValue = MaskCredentials(fileValue.(string))
|
|
|
|
}
|
2015-12-10 23:35:10 +00:00
|
|
|
return fmt.Sprintf("%s: (from flag: %v, from file: %v)", name, flagValue, fileValue)
|
|
|
|
}
|
|
|
|
|
2016-01-20 22:16:49 +00:00
|
|
|
// 3. Search keys that are present as a flag and as a file option.
|
2016-06-21 20:42:47 +00:00
|
|
|
duplicatedConflicts := func(f *pflag.Flag) {
|
2015-12-10 23:35:10 +00:00
|
|
|
// search option name in the json configuration payload if the value is a named option
|
|
|
|
if namedOption, ok := f.Value.(opts.NamedOption); ok {
|
2018-09-17 22:28:26 +00:00
|
|
|
if optsValue, ok := config[namedOption.Name()]; ok && !skipDuplicates[namedOption.Name()] {
|
2015-12-10 23:35:10 +00:00
|
|
|
conflicts = append(conflicts, printConflict(namedOption.Name(), f.Value.String(), optsValue))
|
|
|
|
}
|
|
|
|
} else {
|
2016-06-21 20:42:47 +00:00
|
|
|
// search flag name in the json configuration payload
|
|
|
|
for _, name := range []string{f.Name, f.Shorthand} {
|
2018-09-17 22:28:26 +00:00
|
|
|
if value, ok := config[name]; ok && !skipDuplicates[name] {
|
2015-12-10 23:35:10 +00:00
|
|
|
conflicts = append(conflicts, printConflict(name, f.Value.String(), value))
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 22:16:49 +00:00
|
|
|
flags.Visit(duplicatedConflicts)
|
2015-12-10 23:35:10 +00:00
|
|
|
|
|
|
|
if len(conflicts) > 0 {
|
2022-10-05 14:28:35 +00:00
|
|
|
return errors.Errorf("the following directives are specified both as a flag and in the configuration file: %s", strings.Join(conflicts, ", "))
|
2015-12-10 23:35:10 +00:00
|
|
|
}
|
|
|
|
return nil
|
2014-08-10 01:18:32 +00:00
|
|
|
}
|
2016-03-11 08:50:49 +00:00
|
|
|
|
daemon: raise default minimum API version to v1.24
The daemon currently provides support for API versions all the way back
to v1.12, which is the version of the API that shipped with docker 1.0. On
Windows, the minimum supported version is v1.24.
Such old versions of the client are rare, and supporting older API versions
has accumulated significant amounts of code to remain backward-compatible
(which is largely untested, and a "best-effort" at most).
This patch updates the minimum API version to v1.24, which is the fallback
API version used when API-version negotiation fails. The intent is to start
deprecating older API versions, but no code is removed yet as part of this
patch, and a DOCKER_MIN_API_VERSION environment variable is added, which
allows overriding the minimum version (to allow restoring the behavior from
before this patch).
With this patch the daemon defaults to API v1.24 as minimum:
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.24)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Trying to use an older version of the API produces an error:
DOCKER_API_VERSION=1.23 docker version
Client:
Version: 24.0.2
API version: 1.23 (downgraded from 1.43)
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Error response from daemon: client version 1.23 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version
To restore the previous minimum, users can start the daemon with the
DOCKER_MIN_API_VERSION environment variable set:
DOCKER_MIN_API_VERSION=1.12 dockerd
API 1.12 is the oldest supported API version on Linux;
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.12)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
When using the `DOCKER_MIN_API_VERSION` with a version of the API that
is not supported, an error is produced when starting the daemon;
DOCKER_MIN_API_VERSION=1.11 dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: 1.11
DOCKER_MIN_API_VERSION=1.45 dockerd --validate
invalid DOCKER_MIN_API_VERSION: maximum supported API version is 1.44: 1.45
Specifying a malformed API version also produces the same error;
DOCKER_MIN_API_VERSION=hello dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: hello
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-12-04 12:44:21 +00:00
|
|
|
// ValidateMinAPIVersion verifies if the given API version is within the
|
|
|
|
// range supported by the daemon. It is used to validate a custom minimum
|
|
|
|
// API version set through DOCKER_MIN_API_VERSION.
|
|
|
|
func ValidateMinAPIVersion(ver string) error {
|
|
|
|
if ver == "" {
|
|
|
|
return errors.New(`value is empty`)
|
|
|
|
}
|
|
|
|
if strings.EqualFold(ver[0:1], "v") {
|
|
|
|
return errors.New(`API version must be provided without "v" prefix`)
|
|
|
|
}
|
2024-01-21 23:36:13 +00:00
|
|
|
if versions.LessThan(ver, defaultMinAPIVersion) {
|
|
|
|
return errors.Errorf(`minimum supported API version is %s: %s`, defaultMinAPIVersion, ver)
|
daemon: raise default minimum API version to v1.24
The daemon currently provides support for API versions all the way back
to v1.12, which is the version of the API that shipped with docker 1.0. On
Windows, the minimum supported version is v1.24.
Such old versions of the client are rare, and supporting older API versions
has accumulated significant amounts of code to remain backward-compatible
(which is largely untested, and a "best-effort" at most).
This patch updates the minimum API version to v1.24, which is the fallback
API version used when API-version negotiation fails. The intent is to start
deprecating older API versions, but no code is removed yet as part of this
patch, and a DOCKER_MIN_API_VERSION environment variable is added, which
allows overriding the minimum version (to allow restoring the behavior from
before this patch).
With this patch the daemon defaults to API v1.24 as minimum:
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.24)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Trying to use an older version of the API produces an error:
DOCKER_API_VERSION=1.23 docker version
Client:
Version: 24.0.2
API version: 1.23 (downgraded from 1.43)
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Error response from daemon: client version 1.23 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version
To restore the previous minimum, users can start the daemon with the
DOCKER_MIN_API_VERSION environment variable set:
DOCKER_MIN_API_VERSION=1.12 dockerd
API 1.12 is the oldest supported API version on Linux;
docker version
Client:
Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfc
Built: Thu May 25 21:50:49 2023
OS/Arch: linux/arm64
Context: default
Server:
Engine:
Version: dev
API version: 1.44 (minimum version 1.12)
Go version: go1.21.3
Git commit: 0322a29b9ef8806aaa4b45dc9d9a2ebcf0244bf4
Built: Mon Dec 4 15:22:17 2023
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v1.7.9
GitCommit: 4f03e100cb967922bec7459a78d16ccbac9bb81d
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
When using the `DOCKER_MIN_API_VERSION` with a version of the API that
is not supported, an error is produced when starting the daemon;
DOCKER_MIN_API_VERSION=1.11 dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: 1.11
DOCKER_MIN_API_VERSION=1.45 dockerd --validate
invalid DOCKER_MIN_API_VERSION: maximum supported API version is 1.44: 1.45
Specifying a malformed API version also produces the same error;
DOCKER_MIN_API_VERSION=hello dockerd --validate
invalid DOCKER_MIN_API_VERSION: minimum supported API version is 1.12: hello
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-12-04 12:44:21 +00:00
|
|
|
}
|
|
|
|
if versions.GreaterThan(ver, api.DefaultVersion) {
|
|
|
|
return errors.Errorf(`maximum supported API version is %s: %s`, api.DefaultVersion, ver)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-01-23 11:23:07 +00:00
|
|
|
// Validate validates some specific configs.
|
2016-05-06 04:45:55 +00:00
|
|
|
// such as config.DNS, config.Labels, config.DNSSearch,
|
2019-06-25 13:26:36 +00:00
|
|
|
// as well as config.MaxConcurrentDownloads, config.MaxConcurrentUploads and config.MaxDownloadAttempts.
|
2017-01-23 11:23:07 +00:00
|
|
|
func Validate(config *Config) error {
|
2022-04-22 13:59:23 +00:00
|
|
|
// validate log-level
|
|
|
|
if config.LogLevel != "" {
|
2023-09-15 11:51:51 +00:00
|
|
|
// FIXME(thaJeztah): find a better way for this; this depends on knowledge of containerd's log package internals.
|
|
|
|
// Alternatively: try log.SetLevel(config.LogLevel), and restore the original level, but this also requires internal knowledge.
|
|
|
|
switch strings.ToLower(config.LogLevel) {
|
|
|
|
case "panic", "fatal", "error", "warn", "info", "debug", "trace":
|
|
|
|
// These are valid. See [log.SetLevel] for a list of accepted levels.
|
|
|
|
default:
|
2022-10-05 14:28:35 +00:00
|
|
|
return errors.Errorf("invalid logging level: %s", config.LogLevel)
|
2022-04-22 13:59:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-13 21:54:14 +00:00
|
|
|
// validate log-format
|
|
|
|
if logFormat := config.LogFormat; logFormat != "" {
|
2023-08-30 20:11:24 +00:00
|
|
|
switch logFormat {
|
2023-06-13 21:54:14 +00:00
|
|
|
case log.TextFormat, log.JSONFormat:
|
|
|
|
// These are valid
|
|
|
|
default:
|
|
|
|
return errors.Errorf("invalid log format: %s", logFormat)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-11 08:50:49 +00:00
|
|
|
// validate DNSSearch
|
|
|
|
for _, dnsSearch := range config.DNSSearch {
|
|
|
|
if _, err := opts.ValidateDNSSearch(dnsSearch); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate Labels
|
|
|
|
for _, label := range config.Labels {
|
|
|
|
if _, err := opts.ValidateLabel(label); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2022-04-24 20:42:05 +00:00
|
|
|
|
|
|
|
// TODO(thaJeztah) Validations below should not accept "0" to be valid; see Validate() for a more in-depth description of this problem
|
2023-07-05 12:21:04 +00:00
|
|
|
if config.MTU < 0 {
|
|
|
|
return errors.Errorf("invalid default MTU: %d", config.MTU)
|
2022-06-06 14:53:25 +00:00
|
|
|
}
|
2022-04-24 20:59:54 +00:00
|
|
|
if config.MaxConcurrentDownloads < 0 {
|
2022-10-05 14:28:35 +00:00
|
|
|
return errors.Errorf("invalid max concurrent downloads: %d", config.MaxConcurrentDownloads)
|
2016-05-06 04:45:55 +00:00
|
|
|
}
|
2022-04-24 20:59:54 +00:00
|
|
|
if config.MaxConcurrentUploads < 0 {
|
2022-10-05 14:28:35 +00:00
|
|
|
return errors.Errorf("invalid max concurrent uploads: %d", config.MaxConcurrentUploads)
|
2016-05-06 04:45:55 +00:00
|
|
|
}
|
2022-04-24 20:59:54 +00:00
|
|
|
if config.MaxDownloadAttempts < 0 {
|
2022-10-05 14:28:35 +00:00
|
|
|
return errors.Errorf("invalid max download attempts: %d", config.MaxDownloadAttempts)
|
2019-06-25 13:26:36 +00:00
|
|
|
}
|
2016-05-23 21:49:50 +00:00
|
|
|
|
2017-08-29 19:28:33 +00:00
|
|
|
if _, err := ParseGenericResources(config.NodeGenericResources); err != nil {
|
2017-05-31 00:02:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-04 13:18:01 +00:00
|
|
|
for _, h := range config.Hosts {
|
|
|
|
if _, err := opts.ValidateHost(h); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Implement none, private, and shareable ipc modes
Since the commit d88fe447df0e8 ("Add support for sharing /dev/shm/ and
/dev/mqueue between containers") container's /dev/shm is mounted on the
host first, then bind-mounted inside the container. This is done that
way in order to be able to share this container's IPC namespace
(and the /dev/shm mount point) with another container.
Unfortunately, this functionality breaks container checkpoint/restore
(even if IPC is not shared). Since /dev/shm is an external mount, its
contents is not saved by `criu checkpoint`, and so upon restore any
application that tries to access data under /dev/shm is severily
disappointed (which usually results in a fatal crash).
This commit solves the issue by introducing new IPC modes for containers
(in addition to 'host' and 'container:ID'). The new modes are:
- 'shareable': enables sharing this container's IPC with others
(this used to be the implicit default);
- 'private': disables sharing this container's IPC.
In 'private' mode, container's /dev/shm is truly mounted inside the
container, without any bind-mounting from the host, which solves the
issue.
While at it, let's also implement 'none' mode. The motivation, as
eloquently put by Justin Cormack, is:
> I wondered a while back about having a none shm mode, as currently it is
> not possible to have a totally unwriteable container as there is always
> a /dev/shm writeable mount. It is a bit of a niche case (and clearly
> should never be allowed to be daemon default) but it would be trivial to
> add now so maybe we should...
...so here's yet yet another mode:
- 'none': no /dev/shm mount inside the container (though it still
has its own private IPC namespace).
Now, to ultimately solve the abovementioned checkpoint/restore issue, we'd
need to make 'private' the default mode, but unfortunately it breaks the
backward compatibility. So, let's make the default container IPC mode
per-daemon configurable (with the built-in default set to 'shareable'
for now). The default can be changed either via a daemon CLI option
(--default-shm-mode) or a daemon.json configuration file parameter
of the same name.
Note one can only set either 'shareable' or 'private' IPC modes as a
daemon default (i.e. in this context 'host', 'container', or 'none'
do not make much sense).
Some other changes this patch introduces are:
1. A mount for /dev/shm is added to default OCI Linux spec.
2. IpcMode.Valid() is simplified to remove duplicated code that parsed
'container:ID' form. Note the old version used to check that ID does
not contain a semicolon -- this is no longer the case (tests are
modified accordingly). The motivation is we should either do a
proper check for container ID validity, or don't check it at all
(since it is checked in other places anyway). I chose the latter.
3. IpcMode.Container() is modified to not return container ID if the
mode value does not start with "container:", unifying the check to
be the same as in IpcMode.IsContainer().
3. IPC mode unit tests (runconfig/hostconfig_test.go) are modified
to add checks for newly added values.
[v2: addressed review at https://github.com/moby/moby/pull/34087#pullrequestreview-51345997]
[v3: addressed review at https://github.com/moby/moby/pull/34087#pullrequestreview-53902833]
[v4: addressed the case of upgrading from older daemon, in this case
container.HostConfig.IpcMode is unset and this is valid]
[v5: document old and new IpcMode values in api/swagger.yaml]
[v6: add the 'none' mode, changelog entry to docs/api/version-history.md]
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2017-06-27 21:58:50 +00:00
|
|
|
// validate platform-specific settings
|
2018-01-14 23:42:25 +00:00
|
|
|
return config.ValidatePlatformConfig()
|
2016-03-11 08:50:49 +00:00
|
|
|
}
|
2017-01-22 06:59:29 +00:00
|
|
|
|
2021-08-31 12:05:49 +00:00
|
|
|
// MaskCredentials masks credentials that are in an URL.
|
|
|
|
func MaskCredentials(rawURL string) string {
|
|
|
|
parsedURL, err := url.Parse(rawURL)
|
|
|
|
if err != nil || parsedURL.User == nil {
|
|
|
|
return rawURL
|
|
|
|
}
|
|
|
|
parsedURL.User = url.UserPassword("xxxxx", "xxxxx")
|
|
|
|
return parsedURL.String()
|
|
|
|
}
|