2013-01-20 00:07:19 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-04-10 10:24:15 +00:00
|
|
|
"fmt"
|
2016-08-03 16:20:46 +00:00
|
|
|
"os"
|
2014-02-01 11:38:39 +00:00
|
|
|
|
2016-06-21 20:42:47 +00:00
|
|
|
"github.com/docker/docker/cli"
|
2017-01-23 11:23:07 +00:00
|
|
|
"github.com/docker/docker/daemon/config"
|
2015-11-09 18:32:46 +00:00
|
|
|
"github.com/docker/docker/dockerversion"
|
2018-11-24 13:39:08 +00:00
|
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
2014-10-30 12:48:30 +00:00
|
|
|
"github.com/docker/docker/pkg/reexec"
|
2015-01-24 01:33:49 +00:00
|
|
|
"github.com/docker/docker/pkg/term"
|
2019-04-19 07:53:58 +00:00
|
|
|
"github.com/docker/docker/rootless"
|
2018-07-11 22:25:38 +00:00
|
|
|
"github.com/moby/buildkit/util/apicaps"
|
2017-07-26 21:42:13 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-06-21 20:42:47 +00:00
|
|
|
"github.com/spf13/cobra"
|
2013-01-24 07:14:46 +00:00
|
|
|
)
|
|
|
|
|
2019-04-19 07:53:58 +00:00
|
|
|
var (
|
|
|
|
honorXDG bool
|
|
|
|
)
|
|
|
|
|
2018-10-15 07:52:53 +00:00
|
|
|
func newDaemonCommand() (*cobra.Command, error) {
|
2017-06-01 20:34:31 +00:00
|
|
|
opts := newDaemonOptions(config.New())
|
2015-03-20 01:07:56 +00:00
|
|
|
|
2016-06-21 20:42:47 +00: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 23:19:16 +00:00
|
|
|
DisableFlagsInUseLine: true,
|
2018-05-19 01:15:08 +00:00
|
|
|
Version: fmt.Sprintf("%s, build %s", dockerversion.Version, dockerversion.GitCommit),
|
2015-05-07 16:49:07 +00:00
|
|
|
}
|
2016-06-23 15:25:51 +00:00
|
|
|
cli.SetupRootCommand(cmd)
|
2015-05-07 16:49:07 +00:00
|
|
|
|
2016-06-21 20:42:47 +00:00
|
|
|
flags := cmd.Flags()
|
2018-05-19 01:15:08 +00:00
|
|
|
flags.BoolP("version", "v", false, "Print version information and quit")
|
2018-10-15 07:52:53 +00:00
|
|
|
defaultDaemonConfigFile, err := getDefaultDaemonConfigFile()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-30 10:01:00 +00:00
|
|
|
flags.StringVar(&opts.configFile, "config-file", defaultDaemonConfigFile, "Daemon configuration file")
|
2017-06-01 20:34:31 +00:00
|
|
|
opts.InstallFlags(flags)
|
2018-10-15 07:52:53 +00:00
|
|
|
if err := installConfigFlags(opts.daemonConfig, flags); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-06-22 22:36:51 +00:00
|
|
|
installServiceFlags(flags)
|
2015-05-05 04:18:28 +00:00
|
|
|
|
2018-10-15 07:52:53 +00:00
|
|
|
return cmd, nil
|
2016-06-21 20:42:47 +00:00
|
|
|
}
|
2014-06-27 13:55:20 +00:00
|
|
|
|
2018-07-11 22:25:38 +00:00
|
|
|
func init() {
|
|
|
|
if dockerversion.ProductName != "" {
|
|
|
|
apicaps.ExportedProduct = dockerversion.ProductName
|
|
|
|
}
|
2019-04-19 07:53:58 +00: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 22:25:38 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 20:42:47 +00:00
|
|
|
func main() {
|
|
|
|
if reexec.Init() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-24 13:39:08 +00: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 20:42:47 +00:00
|
|
|
// Set terminal emulation based on platform as required.
|
|
|
|
_, stdout, stderr := term.StdStreams()
|
2017-03-30 22:36:42 +00:00
|
|
|
|
2019-02-21 00:39:07 +00:00
|
|
|
initLogging(stdout, stderr)
|
2016-06-21 20:42:47 +00:00
|
|
|
|
2018-10-15 07:52:53 +00:00
|
|
|
onError := func(err error) {
|
2016-08-03 16:20:46 +00:00
|
|
|
fmt.Fprintf(stderr, "%s\n", err)
|
|
|
|
os.Exit(1)
|
2016-06-21 20:42:47 +00:00
|
|
|
}
|
2018-10-15 07:52:53 +00:00
|
|
|
|
|
|
|
cmd, err := newDaemonCommand()
|
|
|
|
if err != nil {
|
|
|
|
onError(err)
|
|
|
|
}
|
|
|
|
cmd.SetOutput(stdout)
|
|
|
|
if err := cmd.Execute(); err != nil {
|
|
|
|
onError(err)
|
|
|
|
}
|
2016-06-21 20:42:47 +00:00
|
|
|
}
|