diff --git a/cmd/containerd/main.go b/cmd/containerd/main.go index f9b5f5c..2a4135c 100644 --- a/cmd/containerd/main.go +++ b/cmd/containerd/main.go @@ -162,10 +162,22 @@ func before(context *cli.Context) error { log.G(global).Infof("containerd default config written to %q", fh.Name()) os.Exit(0) } - if err := loadConfig(context.GlobalString("config")); err != nil && - !os.IsNotExist(err) { + err := loadConfig(context.GlobalString("config")) + if err != nil && !os.IsNotExist(err) { return err + } else if err != nil && os.IsNotExist(err) { + log.G(global).Infof("config %q does not exist. Creating it.", context.GlobalString("config")) + fh, err := os.Create(context.GlobalString("config")) + if err != nil { + return err + } + if _, err := conf.WriteTo(fh); err != nil { + fh.Close() + return err + } + fh.Close() } + // the order for config vs flag values is that flags will always override // the config values if they are set if err := setLevel(context); err != nil {