From 5bb832e024c43badb74a12388f575677715c77f8 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Mon, 25 Jan 2016 11:45:20 -0800 Subject: [PATCH] Fix error message in container creation Error message was different if image was specified with the full ID. Fixes #19652 Signed-off-by: Tonis Tiigi --- daemon/daemon.go | 3 +++ integration-cli/docker_api_create_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/daemon/daemon.go b/daemon/daemon.go index 4507cb452d..671383149f 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -1228,6 +1228,9 @@ func (daemon *Daemon) ImageHistory(name string) ([]*types.ImageHistory, error) { func (daemon *Daemon) GetImageID(refOrID string) (image.ID, error) { // Treat as an ID if id, err := digest.ParseDigest(refOrID); err == nil { + if _, err := daemon.imageStore.Get(image.ID(id)); err != nil { + return "", ErrImageDoesNotExist{refOrID} + } return image.ID(id), nil } diff --git a/integration-cli/docker_api_create_test.go b/integration-cli/docker_api_create_test.go index bfa11ff0ff..d29b35501b 100644 --- a/integration-cli/docker_api_create_test.go +++ b/integration-cli/docker_api_create_test.go @@ -32,4 +32,14 @@ func (s *DockerSuite) TestApiCreateWithNotExistImage(c *check.C) { expected = "No such image: test456:latest" c.Assert(strings.TrimSpace(string(resp)), checker.Equals, expected) + config3 := map[string]interface{}{ + "Image": "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa", + } + + status, resp, err = sockRequest("POST", "/containers/create?name="+name, config3) + c.Assert(err, check.IsNil) + c.Assert(status, check.Equals, http.StatusNotFound) + expected = "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa" + c.Assert(strings.TrimSpace(string(resp)), checker.Equals, expected) + }