diff --git a/cli/command/container/create.go b/cli/command/container/create.go index c505b61e142e..9861c4a01b17 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -20,6 +20,7 @@ import ( "github.com/spf13/pflag" ) +// Pull constants const ( PullImageAlways = "always" PullImageMissing = "missing" @@ -168,6 +169,7 @@ func newCIDFile(path string) (*cidFile, error) { return &cidFile{path: path, file: f}, nil } +// nolint: gocyclo func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig *containerConfig, opts *createOptions) (*container.ContainerCreateCreatedBody, error) { config := containerConfig.Config hostConfig := containerConfig.HostConfig @@ -242,6 +244,9 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerConfig } } response, err = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, opts.name) + if err != nil { + return nil, err + } } else if opts.pull == PullImageNever { // Never try and pull the image response, err = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, opts.name) diff --git a/cli/command/container/create_test.go b/cli/command/container/create_test.go index f2c96c5ed2c0..0f32a44d10dd 100644 --- a/cli/command/container/create_test.go +++ b/cli/command/container/create_test.go @@ -73,7 +73,6 @@ func TestCIDFileCloseWithWrite(t *testing.T) { assert.NilError(t, err) } -//Modify this test func TestCreateContainerPullsImageIfMissing(t *testing.T) { imageName := "does-not-exist-locally" responseCounter := 0 @@ -123,11 +122,9 @@ func TestCreateContainerPullsImageIfMissing(t *testing.T) { assert.Check(t, is.Contains(stderr, "Unable to find image 'does-not-exist-locally:latest' locally")) } -//Modify this test func TestCreateContainerNeverPullsImage(t *testing.T) { imageName := "does-not-exist-locally" responseCounter := 0 - containerID := "abcdef" client := &fakeClient{ createContainerFunc: func(