Skip to content

Commit ca0fb17

Browse files
authored
Merge pull request #6700 from thaJeztah/fix_validation
docker run, create: don't swallow connection errors during validate
2 parents 91d44d6 + a6335c4 commit ca0fb17

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

cli/command/container/client_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,7 @@ func (f *fakeClient) ContainerPause(ctx context.Context, containerID string, opt
232232

233233
return client.ContainerPauseResult{}, nil
234234
}
235+
236+
func (*fakeClient) Ping(_ context.Context, _ client.PingOptions) (client.PingResult, error) {
237+
return client.PingResult{}, nil
238+
}

cli/command/container/create.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ func runCreate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet,
112112
}
113113
}
114114
copts.env = *opts.NewListOptsRef(&newEnv, nil)
115-
containerCfg, err := parse(flags, copts, dockerCli.ServerInfo().OSType)
115+
serverInfo, err := dockerCli.Client().Ping(ctx, client.PingOptions{})
116+
if err != nil {
117+
return err
118+
}
119+
120+
containerCfg, err := parse(flags, copts, serverInfo.OSType)
116121
if err != nil {
117122
return cli.StatusError{
118123
Status: withHelp(err, "create").Error(),

cli/command/container/run.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ func runRun(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, ro
101101
}
102102
}
103103
copts.env = *opts.NewListOptsRef(&newEnv, nil)
104-
containerCfg, err := parse(flags, copts, dockerCli.ServerInfo().OSType)
104+
serverInfo, err := dockerCli.Client().Ping(ctx, client.PingOptions{})
105+
if err != nil {
106+
return err
107+
}
108+
109+
containerCfg, err := parse(flags, copts, serverInfo.OSType)
105110
// just in case the parse does not exit
106111
if err != nil {
107112
return cli.StatusError{

0 commit comments

Comments
 (0)