瀏覽代碼

cmd/dockerd: validate API configuration as part of --validate

Previously, the API server configuration would be initialized and
validated when starting the API. Because of this, invalid configuration
(e.g. missing or invalid TLS certificates) would not be detected
when using `dockerd --validate`.

This patch moves creation of the validation earlier, so that it's
validated as part of `dockerd --validate`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 年之前
父節點
當前提交
0603f87fab
共有 1 個文件被更改,包括 5 次插入4 次删除
  1. 5 4
      cmd/dockerd/daemon.go

+ 5 - 4
cmd/dockerd/daemon.go

@@ -85,6 +85,11 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
 		return err
 		return err
 	}
 	}
 
 
+	serverConfig, err := newAPIServerConfig(cli.Config)
+	if err != nil {
+		return err
+	}
+
 	if opts.Validate {
 	if opts.Validate {
 		// If config wasn't OK we wouldn't have made it this far.
 		// If config wasn't OK we wouldn't have made it this far.
 		fmt.Fprintln(os.Stderr, "configuration OK")
 		fmt.Fprintln(os.Stderr, "configuration OK")
@@ -159,10 +164,6 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
 		}
 		}
 	}
 	}
 
 
-	serverConfig, err := newAPIServerConfig(cli.Config)
-	if err != nil {
-		return errors.Wrap(err, "failed to create API server")
-	}
 	cli.api = apiserver.New(serverConfig)
 	cli.api = apiserver.New(serverConfig)
 
 
 	hosts, err := loadListeners(cli, serverConfig)
 	hosts, err := loadListeners(cli, serverConfig)