2013-01-19 19:07:19 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-04-10 06:24:15 -04:00
|
|
|
"fmt"
|
2016-08-03 12:20:46 -04:00
|
|
|
"os"
|
2014-02-01 06:38:39 -05:00
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
"github.com/docker/docker/cli"
|
2017-01-23 06:23:07 -05:00
|
|
|
"github.com/docker/docker/daemon/config"
|
2015-11-09 13:32:46 -05:00
|
|
|
"github.com/docker/docker/dockerversion"
|
2018-11-24 08:39:08 -05:00
|
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
2014-10-30 08:48:30 -04:00
|
|
|
"github.com/docker/docker/pkg/reexec"
|
2019-04-19 03:53:58 -04:00
|
|
|
"github.com/docker/docker/rootless"
|
2018-07-11 18:25:38 -04:00
|
|
|
"github.com/moby/buildkit/util/apicaps"
|
2020-04-16 05:31:08 -04:00
|
|
|
"github.com/moby/term"
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-06-21 16:42:47 -04:00
|
|
|
"github.com/spf13/cobra"
|
2013-01-24 02:14:46 -05:00
|
|
|
)
|
|
|
|
|
2019-04-19 03:53:58 -04:00
|
|
|
var (
|
|
|
|
honorXDG bool
|
|
|
|
)
|
|
|
|
|
2018-10-15 03:52:53 -04:00
|
|
|
func newDaemonCommand() (*cobra.Command, error) {
|
2017-06-01 16:34:31 -04:00
|
|
|
opts := newDaemonOptions(config.New())
|
2015-03-19 21:07:56 -04:00
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "dockerd [OPTIONS]",
|
|
|
|
Short: "A self-sufficient runtime for containers.",
|
|
|
|
SilenceUsage: true,
|
|
|
|
SilenceErrors: true,
|
|
|
|
Args: cli.NoArgs,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
opts.flags = cmd.Flags()
|
|
|
|
return runDaemon(opts)
|
|
|
|
},
|
2018-05-18 19:19:16 -04:00
|
|
|
DisableFlagsInUseLine: true,
|
2018-05-18 21:15:08 -04:00
|
|
|
Version: fmt.Sprintf("%s, build %s", dockerversion.Version, dockerversion.GitCommit),
|
2015-05-07 12:49:07 -04:00
|
|
|
}
|
2016-06-23 11:25:51 -04:00
|
|
|
cli.SetupRootCommand(cmd)
|
2015-05-07 12:49:07 -04:00
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
flags := cmd.Flags()
|
2018-05-18 21:15:08 -04:00
|
|
|
flags.BoolP("version", "v", false, "Print version information and quit")
|
2018-10-15 03:52:53 -04:00
|
|
|
defaultDaemonConfigFile, err := getDefaultDaemonConfigFile()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-30 06:01:00 -04:00
|
|
|
flags.StringVar(&opts.configFile, "config-file", defaultDaemonConfigFile, "Daemon configuration file")
|
2022-03-25 11:21:45 -04:00
|
|
|
configureCertsDir()
|
2022-04-22 10:49:26 -04:00
|
|
|
opts.installFlags(flags)
|
2018-10-15 03:52:53 -04:00
|
|
|
if err := installConfigFlags(opts.daemonConfig, flags); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-06-22 18:36:51 -04:00
|
|
|
installServiceFlags(flags)
|
2015-05-05 00:18:28 -04:00
|
|
|
|
2018-10-15 03:52:53 -04:00
|
|
|
return cmd, nil
|
2016-06-21 16:42:47 -04:00
|
|
|
}
|
2014-06-27 09:55:20 -04:00
|
|
|
|
2018-07-11 18:25:38 -04:00
|
|
|
func init() {
|
|
|
|
if dockerversion.ProductName != "" {
|
|
|
|
apicaps.ExportedProduct = dockerversion.ProductName
|
|
|
|
}
|
2019-04-19 03:53:58 -04:00
|
|
|
// When running with RootlessKit, $XDG_RUNTIME_DIR, $XDG_DATA_HOME, and $XDG_CONFIG_HOME needs to be
|
|
|
|
// honored as the default dirs, because we are unlikely to have permissions to access the system-wide
|
|
|
|
// directories.
|
|
|
|
//
|
|
|
|
// Note that even running with --rootless, when not running with RootlessKit, honorXDG needs to be kept false,
|
|
|
|
// because the system-wide directories in the current mount namespace are expected to be accessible.
|
|
|
|
// ("rootful" dockerd in rootless dockerd, #38702)
|
|
|
|
honorXDG = rootless.RunningWithRootlessKit()
|
2018-07-11 18:25:38 -04:00
|
|
|
}
|
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
func main() {
|
|
|
|
if reexec.Init() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-24 08:39:08 -05:00
|
|
|
// initial log formatting; this setting is updated after the daemon configuration is loaded.
|
|
|
|
logrus.SetFormatter(&logrus.TextFormatter{
|
|
|
|
TimestampFormat: jsonmessage.RFC3339NanoFixed,
|
|
|
|
FullTimestamp: true,
|
|
|
|
})
|
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
// Set terminal emulation based on platform as required.
|
|
|
|
_, stdout, stderr := term.StdStreams()
|
2017-03-30 18:36:42 -04:00
|
|
|
|
2019-02-20 19:39:07 -05:00
|
|
|
initLogging(stdout, stderr)
|
2016-06-21 16:42:47 -04:00
|
|
|
|
2018-10-15 03:52:53 -04:00
|
|
|
onError := func(err error) {
|
2016-08-03 12:20:46 -04:00
|
|
|
fmt.Fprintf(stderr, "%s\n", err)
|
|
|
|
os.Exit(1)
|
2016-06-21 16:42:47 -04:00
|
|
|
}
|
2018-10-15 03:52:53 -04:00
|
|
|
|
|
|
|
cmd, err := newDaemonCommand()
|
|
|
|
if err != nil {
|
|
|
|
onError(err)
|
|
|
|
}
|
2020-05-08 04:33:46 -04:00
|
|
|
cmd.SetOut(stdout)
|
2018-10-15 03:52:53 -04:00
|
|
|
if err := cmd.Execute(); err != nil {
|
|
|
|
onError(err)
|
|
|
|
}
|
2016-06-21 16:42:47 -04:00
|
|
|
}
|