2021-08-23 09:14:53 -04:00
//go:build linux || freebsd
2017-11-01 19:37:53 -04:00
// +build linux freebsd
2017-01-23 06:23:07 -05:00
package main
import (
2019-04-19 03:53:58 -04:00
"os/exec"
2022-03-25 11:21:45 -04:00
"path/filepath"
2019-04-19 03:53:58 -04:00
2020-11-09 09:00:32 -05:00
"github.com/containerd/cgroups"
2017-01-23 06:23:07 -05:00
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/opts"
2022-03-25 11:21:45 -04:00
"github.com/docker/docker/pkg/homedir"
"github.com/docker/docker/registry"
2018-10-15 03:52:53 -04:00
"github.com/docker/docker/rootless"
2019-08-05 10:37:47 -04:00
units "github.com/docker/go-units"
2019-04-19 03:53:58 -04:00
"github.com/pkg/errors"
2017-01-23 06:23:07 -05:00
"github.com/spf13/pflag"
)
// installConfigFlags adds flags to the pflag.FlagSet to configure the daemon
2018-10-15 03:52:53 -04:00
func installConfigFlags ( conf * config . Config , flags * pflag . FlagSet ) error {
2017-01-23 06:23:07 -05:00
// First handle install flags which are consistent cross-platform
2018-10-15 03:52:53 -04:00
if err := installCommonConfigFlags ( conf , flags ) ; err != nil {
return err
}
2017-01-23 06:23:07 -05:00
// Then install flags common to unix platforms
installUnixConfigFlags ( conf , flags )
conf . Ulimits = make ( map [ string ] * units . Ulimit )
2016-12-13 18:04:59 -05:00
conf . NetworkConfig . DefaultAddressPools = opts . PoolsOpt { }
2017-01-23 06:23:07 -05:00
// Set default value for `--default-shm-size`
conf . ShmSize = opts . MemBytes ( config . DefaultShmSize )
// Then platform-specific install flags
flags . BoolVar ( & conf . EnableSelinuxSupport , "selinux-enabled" , false , "Enable selinux support" )
2017-04-12 03:26:42 -04:00
flags . Var ( opts . NewNamedUlimitOpt ( "default-ulimits" , & conf . Ulimits ) , "default-ulimit" , "Default ulimits for containers" )
2017-01-23 06:23:07 -05:00
flags . BoolVar ( & conf . BridgeConfig . EnableIPTables , "iptables" , true , "Enable addition of iptables rules" )
2022-04-04 05:54:01 -04:00
flags . BoolVar ( & conf . BridgeConfig . EnableIP6Tables , "ip6tables" , false , "Enable addition of ip6tables rules (experimental)" )
2017-01-23 06:23:07 -05:00
flags . BoolVar ( & conf . BridgeConfig . EnableIPForward , "ip-forward" , true , "Enable net.ipv4.ip_forward" )
flags . BoolVar ( & conf . BridgeConfig . EnableIPMasq , "ip-masq" , true , "Enable IP masquerading" )
flags . BoolVar ( & conf . BridgeConfig . EnableIPv6 , "ipv6" , false , "Enable IPv6 networking" )
flags . StringVar ( & conf . BridgeConfig . FixedCIDRv6 , "fixed-cidr-v6" , "" , "IPv6 subnet for fixed IPs" )
flags . BoolVar ( & conf . BridgeConfig . EnableUserlandProxy , "userland-proxy" , true , "Use userland proxy for loopback traffic" )
2019-04-19 03:53:58 -04:00
defaultUserlandProxyPath := ""
if rootless . RunningWithRootlessKit ( ) {
var err error
// use rootlesskit-docker-proxy for exposing the ports in RootlessKit netns to the initial namespace.
defaultUserlandProxyPath , err = exec . LookPath ( rootless . RootlessKitDockerProxyBinary )
if err != nil {
return errors . Wrapf ( err , "running with RootlessKit, but %s not installed" , rootless . RootlessKitDockerProxyBinary )
}
2022-03-25 11:21:45 -04:00
configHome , err := homedir . GetConfigHome ( )
if err == nil {
registry . SetCertsDir ( filepath . Join ( configHome , "docker/certs.d" ) )
}
2019-04-19 03:53:58 -04:00
}
flags . StringVar ( & conf . BridgeConfig . UserlandProxyPath , "userland-proxy-path" , defaultUserlandProxyPath , "Path to the userland proxy binary" )
2017-01-23 06:23:07 -05:00
flags . StringVar ( & conf . CgroupParent , "cgroup-parent" , "" , "Set parent cgroup for all containers" )
flags . StringVar ( & conf . RemappedRoot , "userns-remap" , "" , "User/Group setting for user namespaces" )
flags . BoolVar ( & conf . LiveRestoreEnabled , "live-restore" , false , "Enable live restore of docker when containers are still running" )
2020-10-05 12:55:43 -04:00
flags . IntVar ( & conf . OOMScoreAdjust , "oom-score-adjust" , 0 , "Set the oom_score_adj for the daemon" )
2017-01-23 06:23:07 -05:00
flags . BoolVar ( & conf . Init , "init" , false , "Run an init in the container to forward signals and reap processes" )
flags . StringVar ( & conf . InitPath , "init-path" , "" , "Path to the docker-init binary" )
2022-01-06 16:20:15 -05:00
flags . Int64Var ( & conf . CPURealtimePeriod , "cpu-rt-period" , 0 , "Limit the CPU real-time period in microseconds for the parent cgroup for all containers (not supported with cgroups v2)" )
flags . Int64Var ( & conf . CPURealtimeRuntime , "cpu-rt-runtime" , 0 , "Limit the CPU real-time runtime in microseconds for the parent cgroup for all containers (not supported with cgroups v2)" )
2021-06-07 07:50:00 -04:00
flags . StringVar ( & conf . SeccompProfile , "seccomp-profile" , config . SeccompProfileDefault , ` Path to seccomp profile. Use "unconfined" to disable the default seccomp profile ` )
2017-01-23 06:23:07 -05:00
flags . Var ( & conf . ShmSize , "default-shm-size" , "Default shm size for containers" )
2017-05-01 10:15:03 -04:00
flags . BoolVar ( & conf . NoNewPrivileges , "no-new-privileges" , false , "Set no-new-privileges by default for new containers" )
2019-10-12 20:07:36 -04:00
flags . StringVar ( & conf . IpcMode , "default-ipc-mode" , string ( config . DefaultIpcMode ) , ` Default mode for containers ipc ("shareable" | "private") ` )
2016-12-13 18:04:59 -05:00
flags . Var ( & conf . NetworkConfig . DefaultAddressPools , "default-address-pool" , "Default address pools for node specific local networks" )
2019-04-19 03:53:58 -04:00
// rootless needs to be explicitly specified for running "rootful" dockerd in rootless dockerd (#38702)
// Note that defaultUserlandProxyPath and honorXDG are configured according to the value of rootless.RunningWithRootlessKit, not the value of --rootless.
2020-04-28 22:06:11 -04:00
flags . BoolVar ( & conf . Rootless , "rootless" , rootless . RunningWithRootlessKit ( ) , "Enable rootless mode; typically used with RootlessKit" )
2019-10-13 08:18:57 -04:00
defaultCgroupNamespaceMode := config . DefaultCgroupNamespaceMode
if cgroups . Mode ( ) != cgroups . Unified {
defaultCgroupNamespaceMode = config . DefaultCgroupV1NamespaceMode
2019-11-05 04:04:21 -05:00
}
2019-10-13 08:18:57 -04:00
flags . StringVar ( & conf . CgroupNamespaceMode , "default-cgroupns-mode" , string ( defaultCgroupNamespaceMode ) , ` Default mode for containers cgroup namespace ("host" | "private") ` )
2018-10-15 03:52:53 -04:00
return nil
2017-01-23 06:23:07 -05:00
}
2022-03-25 11:21:45 -04:00
// configureCertsDir configures registry.CertsDir() depending on if the daemon
// is running in rootless mode or not.
func configureCertsDir ( ) {
if rootless . RunningWithRootlessKit ( ) {
configHome , err := homedir . GetConfigHome ( )
if err == nil {
registry . SetCertsDir ( filepath . Join ( configHome , "docker/certs.d" ) )
}
}
}