diff --git a/api/client/create.go b/api/client/create.go index fed4734ec7..c3daf46fd5 100644 --- a/api/client/create.go +++ b/api/client/create.go @@ -7,6 +7,7 @@ import ( "io" "net/url" "os" + "strings" "github.com/docker/docker/api/types" "github.com/docker/docker/graph" @@ -94,7 +95,7 @@ func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runc //create the container stream, statusCode, err := cli.call("POST", "/containers/create?"+containerValues.Encode(), mergedConfig, nil) //if image not found try to pull it - if statusCode == 404 { + if statusCode == 404 && strings.Contains(err.Error(), config.Image) { repo, tag := parsers.ParseRepositoryTag(config.Image) if tag == "" { tag = graph.DEFAULTTAG diff --git a/builder/dispatchers.go b/builder/dispatchers.go index acb4d50de2..e479911949 100644 --- a/builder/dispatchers.go +++ b/builder/dispatchers.go @@ -166,7 +166,7 @@ func from(b *Builder, args []string, attributes map[string]bool, original string } } if err != nil { - if b.Daemon.Graph().IsNotExist(err) { + if b.Daemon.Graph().IsNotExist(err, name) { image, err = b.pullImage(name) } diff --git a/daemon/create.go b/daemon/create.go index 39b6ac58b8..c820201e42 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -46,7 +46,7 @@ func (daemon *Daemon) ContainerCreate(job *engine.Job) error { container, buildWarnings, err := daemon.Create(config, hostConfig, name) if err != nil { - if daemon.Graph().IsNotExist(err) { + if daemon.Graph().IsNotExist(err, config.Image) { _, tag := parsers.ParseRepositoryTag(config.Image) if tag == "" { tag = graph.DEFAULTTAG diff --git a/daemon/image_delete.go b/daemon/image_delete.go index 1c865c58dd..075672a4cf 100644 --- a/daemon/image_delete.go +++ b/daemon/image_delete.go @@ -138,7 +138,7 @@ func (daemon *Daemon) canDeleteImage(imgID string, force bool) error { for _, container := range daemon.List() { parent, err := daemon.Repositories().LookupImage(container.ImageID) if err != nil { - if daemon.Graph().IsNotExist(err) { + if daemon.Graph().IsNotExist(err, container.ImageID) { return nil } return err diff --git a/graph/graph.go b/graph/graph.go index 933269a435..994ce30289 100644 --- a/graph/graph.go +++ b/graph/graph.go @@ -74,8 +74,8 @@ func (graph *Graph) restore() error { // FIXME: Implement error subclass instead of looking at the error text // Note: This is the way golang implements os.IsNotExists on Plan9 -func (graph *Graph) IsNotExist(err error) bool { - return err != nil && (strings.Contains(strings.ToLower(err.Error()), "does not exist") || strings.Contains(strings.ToLower(err.Error()), "no such")) +func (graph *Graph) IsNotExist(err error, id string) bool { + return err != nil && (strings.Contains(strings.ToLower(err.Error()), "does not exist") || strings.Contains(strings.ToLower(err.Error()), "no such")) && strings.Contains(err.Error(), id) } // Exists returns true if an image is registered at the given id. diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index d8e93c0fc3..17c22e9b35 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -2990,6 +2990,17 @@ func TestRunModeIpcContainer(t *testing.T) { logDone("run - ipc container mode") } +func TestRunModeIpcContainerNotExists(t *testing.T) { + defer deleteAllContainers() + cmd := exec.Command(dockerBinary, "run", "-d", "--ipc", "container:abcd1234", "busybox", "top") + out, _, err := runCommandWithOutput(cmd) + if !strings.Contains(out, "abcd1234") || err == nil { + t.Fatalf("run IPC from a non exists container should with correct error out") + } + + logDone("run - ipc from a non exists container failed with correct error out") +} + func TestContainerNetworkMode(t *testing.T) { defer deleteAllContainers() testRequires(t, SameHostDaemon)