github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/cmd/dockerd/docker.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/demonoid81/moby/cli" 8 "github.com/demonoid81/moby/daemon/config" 9 "github.com/demonoid81/moby/dockerversion" 10 "github.com/demonoid81/moby/pkg/jsonmessage" 11 "github.com/demonoid81/moby/pkg/reexec" 12 "github.com/demonoid81/moby/rootless" 13 "github.com/moby/buildkit/util/apicaps" 14 "github.com/moby/term" 15 "github.com/sirupsen/logrus" 16 "github.com/spf13/cobra" 17 ) 18 19 var ( 20 honorXDG bool 21 ) 22 23 func newDaemonCommand() (*cobra.Command, error) { 24 opts := newDaemonOptions(config.New()) 25 26 cmd := &cobra.Command{ 27 Use: "dockerd [OPTIONS]", 28 Short: "A self-sufficient runtime for containers.", 29 SilenceUsage: true, 30 SilenceErrors: true, 31 Args: cli.NoArgs, 32 RunE: func(cmd *cobra.Command, args []string) error { 33 opts.flags = cmd.Flags() 34 return runDaemon(opts) 35 }, 36 DisableFlagsInUseLine: true, 37 Version: fmt.Sprintf("%s, build %s", dockerversion.Version, dockerversion.GitCommit), 38 } 39 cli.SetupRootCommand(cmd) 40 41 flags := cmd.Flags() 42 flags.BoolP("version", "v", false, "Print version information and quit") 43 defaultDaemonConfigFile, err := getDefaultDaemonConfigFile() 44 if err != nil { 45 return nil, err 46 } 47 flags.StringVar(&opts.configFile, "config-file", defaultDaemonConfigFile, "Daemon configuration file") 48 opts.InstallFlags(flags) 49 if err := installConfigFlags(opts.daemonConfig, flags); err != nil { 50 return nil, err 51 } 52 installServiceFlags(flags) 53 54 return cmd, nil 55 } 56 57 func init() { 58 if dockerversion.ProductName != "" { 59 apicaps.ExportedProduct = dockerversion.ProductName 60 } 61 // When running with RootlessKit, $XDG_RUNTIME_DIR, $XDG_DATA_HOME, and $XDG_CONFIG_HOME needs to be 62 // honored as the default dirs, because we are unlikely to have permissions to access the system-wide 63 // directories. 64 // 65 // Note that even running with --rootless, when not running with RootlessKit, honorXDG needs to be kept false, 66 // because the system-wide directories in the current mount namespace are expected to be accessible. 67 // ("rootful" dockerd in rootless dockerd, #38702) 68 honorXDG = rootless.RunningWithRootlessKit() 69 } 70 71 func main() { 72 if reexec.Init() { 73 return 74 } 75 76 // initial log formatting; this setting is updated after the daemon configuration is loaded. 77 logrus.SetFormatter(&logrus.TextFormatter{ 78 TimestampFormat: jsonmessage.RFC3339NanoFixed, 79 FullTimestamp: true, 80 }) 81 82 // Set terminal emulation based on platform as required. 83 _, stdout, stderr := term.StdStreams() 84 85 initLogging(stdout, stderr) 86 87 onError := func(err error) { 88 fmt.Fprintf(stderr, "%s\n", err) 89 os.Exit(1) 90 } 91 92 cmd, err := newDaemonCommand() 93 if err != nil { 94 onError(err) 95 } 96 cmd.SetOut(stdout) 97 if err := cmd.Execute(); err != nil { 98 onError(err) 99 } 100 }