2018-04-10 14:29:48 +00:00
|
|
|
package daemon
|
|
|
|
|
2019-09-17 15:50:24 +00:00
|
|
|
import (
|
2020-03-13 13:37:09 +00:00
|
|
|
"os/user"
|
|
|
|
|
2019-09-17 15:50:24 +00:00
|
|
|
"github.com/docker/docker/testutil/environment"
|
|
|
|
)
|
2018-04-13 15:02:56 +00:00
|
|
|
|
2019-09-17 17:44:35 +00:00
|
|
|
// Option is used to configure a daemon.
|
|
|
|
type Option func(*Daemon)
|
|
|
|
|
2019-11-05 21:40:27 +00:00
|
|
|
// WithContainerdSocket sets the --containerd option on the daemon.
|
|
|
|
// Use an empty string to remove the option.
|
|
|
|
//
|
|
|
|
// If unset the --containerd option will be used with a default value.
|
|
|
|
func WithContainerdSocket(socket string) Option {
|
|
|
|
return func(d *Daemon) {
|
|
|
|
d.containerdSocket = socket
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 03:44:18 +00:00
|
|
|
// WithDefaultCgroupNamespaceMode sets the default cgroup namespace mode for the daemon
|
2019-09-17 17:44:35 +00:00
|
|
|
func WithDefaultCgroupNamespaceMode(mode string) Option {
|
2019-03-15 03:44:18 +00:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.defaultCgroupNamespaceMode = mode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-17 15:50:24 +00:00
|
|
|
// WithTestLogger causes the daemon to log certain actions to the provided test.
|
2019-10-16 20:27:22 +00:00
|
|
|
func WithTestLogger(t LogT) Option {
|
2019-09-17 15:50:24 +00:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.log = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-10 14:29:48 +00:00
|
|
|
// WithExperimental sets the daemon in experimental mode
|
2019-09-30 12:23:56 +00:00
|
|
|
func WithExperimental() Option {
|
|
|
|
return func(d *Daemon) {
|
|
|
|
d.experimental = true
|
|
|
|
}
|
2018-06-01 10:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WithInit sets the daemon init
|
2019-09-30 12:44:09 +00:00
|
|
|
func WithInit() Option {
|
|
|
|
return func(d *Daemon) {
|
|
|
|
d.init = true
|
|
|
|
}
|
2018-04-10 14:29:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WithDockerdBinary sets the dockerd binary to the specified one
|
2019-09-17 17:44:35 +00:00
|
|
|
func WithDockerdBinary(dockerdBinary string) Option {
|
2018-04-10 14:29:48 +00:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.dockerdBinary = dockerdBinary
|
|
|
|
}
|
|
|
|
}
|
2018-04-11 10:10:17 +00:00
|
|
|
|
|
|
|
// WithSwarmPort sets the swarm port to use for swarm mode
|
2019-09-17 17:44:35 +00:00
|
|
|
func WithSwarmPort(port int) Option {
|
2018-04-11 10:10:17 +00:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.SwarmPort = port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithSwarmListenAddr sets the swarm listen addr to use for swarm mode
|
2019-09-17 17:44:35 +00:00
|
|
|
func WithSwarmListenAddr(listenAddr string) Option {
|
2018-04-11 10:10:17 +00:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.swarmListenAddr = listenAddr
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 15:02:56 +00:00
|
|
|
|
2018-07-30 15:25:02 +00:00
|
|
|
// WithSwarmDefaultAddrPool sets the swarm default address pool to use for swarm mode
|
2019-09-17 17:44:35 +00:00
|
|
|
func WithSwarmDefaultAddrPool(defaultAddrPool []string) Option {
|
2018-07-30 15:25:02 +00:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.DefaultAddrPool = defaultAddrPool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithSwarmDefaultAddrPoolSubnetSize sets the subnet length mask of swarm default address pool to use for swarm mode
|
2019-09-17 17:44:35 +00:00
|
|
|
func WithSwarmDefaultAddrPoolSubnetSize(subnetSize uint32) Option {
|
2018-07-30 15:25:02 +00:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.SubnetSize = subnetSize
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 21:44:40 +00:00
|
|
|
// WithSwarmDataPathPort sets the swarm datapath port to use for swarm mode
|
2019-09-17 17:44:35 +00:00
|
|
|
func WithSwarmDataPathPort(datapathPort uint32) Option {
|
2018-11-20 21:44:40 +00:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.DataPathPort = datapathPort
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-29 20:52:40 +00:00
|
|
|
// WithEnvironment sets options from testutil/environment.Execution struct
|
2019-09-17 17:44:35 +00:00
|
|
|
func WithEnvironment(e environment.Execution) Option {
|
2018-04-13 15:02:56 +00:00
|
|
|
return func(d *Daemon) {
|
|
|
|
if e.DaemonInfo.ExperimentalBuild {
|
|
|
|
d.experimental = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-08 01:27:15 +00:00
|
|
|
|
|
|
|
// WithStorageDriver sets store driver option
|
2019-09-30 12:22:21 +00:00
|
|
|
func WithStorageDriver(driver string) Option {
|
2019-05-08 01:27:15 +00:00
|
|
|
return func(d *Daemon) {
|
|
|
|
d.storageDriver = driver
|
|
|
|
}
|
|
|
|
}
|
2020-03-13 13:37:09 +00:00
|
|
|
|
|
|
|
// WithRootlessUser sets the daemon to be rootless
|
|
|
|
func WithRootlessUser(username string) Option {
|
|
|
|
return func(d *Daemon) {
|
|
|
|
u, err := user.Lookup(username)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
d.rootlessUser = u
|
|
|
|
}
|
|
|
|
}
|
2020-10-05 18:04:52 +00:00
|
|
|
|
|
|
|
// WithOOMScoreAdjust sets OOM score for the daemon
|
|
|
|
func WithOOMScoreAdjust(score int) Option {
|
|
|
|
return func(d *Daemon) {
|
|
|
|
d.OOMScoreAdjust = score
|
|
|
|
}
|
|
|
|
}
|
daemon: support other containerd runtimes (MVP)
Contrary to popular belief, the OCI Runtime specification does not
specify the command-line API for runtimes. Looking at containerd's
architecture from the lens of the OCI Runtime spec, the _shim_ is the
OCI Runtime and runC is "just" an implementation detail of the
io.containerd.runc.v2 runtime. When one configures a non-default runtime
in Docker, what they're really doing is instructing Docker to create
containers using the io.containerd.runc.v2 runtime with a configuration
option telling the runtime that the runC binary is at some non-default
path. Consequently, only OCI runtimes which are compatible with the
io.containerd.runc.v2 shim, such as crun, can be used in this manner.
Other OCI runtimes, including kata-containers v2, come with their own
containerd shim and are not compatible with io.containerd.runc.v2.
As Docker has not historically provided a way to select a non-default
runtime which requires its own shim, runtimes such as kata-containers v2
could not be used with Docker.
Allow other containerd shims to be used with Docker; no daemon
configuration required. If the daemon is instructed to create a
container with a runtime name which does not match any of the configured
or stock runtimes, it passes the name along to containerd verbatim. A
user can start a container with the kata-containers runtime, for
example, simply by calling
docker run --runtime io.containerd.kata.v2
Runtime names which containerd would interpret as a path to an arbitrary
binary are disallowed. While handy for development and testing it is not
strictly necessary and would allow anyone with Engine API access to
trivially execute any binary on the host as root, so we have decided it
would be safest for our users if it was not allowed.
It is not yet possible to set an alternative containerd shim as the
default runtime; it can only be configured per-container.
Signed-off-by: Cory Snider <csnider@mirantis.com>
2022-07-20 20:12:01 +00:00
|
|
|
|
|
|
|
// WithEnvVars sets additional environment variables for the daemon
|
|
|
|
func WithEnvVars(vars ...string) Option {
|
|
|
|
return func(d *Daemon) {
|
|
|
|
d.extraEnv = append(d.extraEnv, vars...)
|
|
|
|
}
|
|
|
|
}
|