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"
|
2016-10-17 18:48:51 +00:00
|
|
|
"runtime"
|
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"
|
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
|
|
|
)
|
|
|
|
|
2016-06-21 20:42:47 +00:00
|
|
|
func newDaemonCommand() *cobra.Command {
|
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")
|
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)
|
2017-01-23 11:23:07 +00:00
|
|
|
installConfigFlags(opts.daemonConfig, flags)
|
2016-06-22 22:36:51 +00:00
|
|
|
installServiceFlags(flags)
|
2015-05-05 04:18:28 +00:00
|
|
|
|
2016-06-21 20:42:47 +00:00
|
|
|
return cmd
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
// @jhowardmsft - maybe there is a historic reason why on non-Windows, stderr is used
|
|
|
|
// here. However, on Windows it makes no sense and there is no need.
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
logrus.SetOutput(stdout)
|
|
|
|
} else {
|
|
|
|
logrus.SetOutput(stderr)
|
|
|
|
}
|
2016-06-21 20:42:47 +00:00
|
|
|
|
|
|
|
cmd := newDaemonCommand()
|
|
|
|
cmd.SetOutput(stdout)
|
|
|
|
if err := cmd.Execute(); err != nil {
|
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
|
|
|
}
|
|
|
|
}
|