Browse Source

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 years ago
parent
commit
0603f87fab
1 changed files with 5 additions and 4 deletions
  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
 	}
 
+	serverConfig, err := newAPIServerConfig(cli.Config)
+	if err != nil {
+		return err
+	}
+
 	if opts.Validate {
 		// If config wasn't OK we wouldn't have made it this far.
 		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)
 
 	hosts, err := loadListeners(cli, serverConfig)