From ffb1f9daaea29ae884536dd97ba2b6509990e07f Mon Sep 17 00:00:00 2001 From: Ace-Tang Date: Sun, 22 Jul 2018 20:35:18 +0800 Subject: [PATCH] bugfix: pull non-exist image in container create Signed-off-by: Ace-Tang --- cli/create.go | 4 ++++ test/cli_create_test.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/cli/create.go b/cli/create.go index 8cb36a636..bb0432e48 100644 --- a/cli/create.go +++ b/cli/create.go @@ -60,6 +60,10 @@ func (cc *CreateCommand) runCreate(args []string) error { ctx := context.Background() apiClient := cc.cli.Client() + if err := pullMissingImage(ctx, apiClient, config.Image, false); err != nil { + return err + } + result, err := apiClient.ContainerCreate(ctx, config.ContainerConfig, config.HostConfig, config.NetworkingConfig, containerName) if err != nil { return fmt.Errorf("failed to create container: %v", err) diff --git a/test/cli_create_test.go b/test/cli_create_test.go index cb5b80b1e..c3d657bfe 100644 --- a/test/cli_create_test.go +++ b/test/cli_create_test.go @@ -489,3 +489,12 @@ func (suite *PouchRunSuite) TestCreateWithPidsLimit(c *check.C) { pl := result[0].HostConfig.PidsLimit c.Assert(int(pl), check.Equals, 10) } + +// TestCreateWithNonExistImage tests running container with image not exist. +func (suite *PouchRunSuite) TestCreateWithNonExistImage(c *check.C) { + cname := "TestCreateWithNonExistImage" + // we should use a non-used image, since containerd not remove image immediately. + image := "docker.io/library/alpine" + res := command.PouchRun("create", cname, image) + res.Assert(c, icmd.Success) +}