From 3732f968d07be0458ac8859e82d99e7e84c96c20 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 20 Jun 2015 23:36:48 +0100 Subject: [PATCH 1/2] include image name in errors The go docker client's ErrNoSuchImage does not include the image name. However, it is imperative that this name appears in error messages sent to clients, since the docker client, as of version 1.7.0, only automatically pulls images when their name is present in the error. Fixes #967. --- proxy/create_container_interceptor.go | 15 ++++++++++++++- proxy/proxy_intercept.go | 7 +++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index cf7e0f22..e12d5fa4 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -21,6 +21,17 @@ type createContainerRequestBody struct { MacAddress string `json:"MacAddress,omitempty" yaml:"MacAddress,omitempty"` } +// Replacement for docker.NoSuchImage, which does not contain the +// image name, which in turn breaks docker clients post 1.7.0 since +// they expect the image name to be present in errors. +type ErrNoSuchImage struct { + Name string +} + +func (err *ErrNoSuchImage) Error() string { + return "No such image: " + err.Name +} + func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { body, err := ioutil.ReadAll(r.Body) if err != nil { @@ -63,7 +74,9 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { func (i *createContainerInterceptor) setWeaveWaitEntrypoint(container *docker.Config) error { if len(container.Entrypoint) == 0 { image, err := i.proxy.client.InspectImage(container.Image) - if err != nil { + if err == docker.ErrNoSuchImage { + return &ErrNoSuchImage{container.Image} + } else if err != nil { return err } diff --git a/proxy/proxy_intercept.go b/proxy/proxy_intercept.go index 080872f4..69f83c83 100644 --- a/proxy/proxy_intercept.go +++ b/proxy/proxy_intercept.go @@ -16,11 +16,10 @@ import ( func (proxy *Proxy) Intercept(i interceptor, w http.ResponseWriter, r *http.Request) { if err := i.InterceptRequest(r); err != nil { - _, isNoSuchContainer := err.(*docker.NoSuchContainer) - switch { - case isNoSuchContainer: + switch err.(type) { + case *docker.NoSuchContainer: http.Error(w, err.Error(), http.StatusNotFound) - case err == docker.ErrNoSuchImage: + case *ErrNoSuchImage: http.Error(w, err.Error(), http.StatusNotFound) default: http.Error(w, err.Error(), http.StatusInternalServerError) From 84775e414b4b15e376f8414ccf4c5edc017d1885 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sun, 21 Jun 2015 10:05:52 +0100 Subject: [PATCH 2/2] Add release 1.0.1 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3339dc0f..59351392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## Release 1.0.1 + +This is a bug fix release, addressing the following issue: + +- executing `docker run` from a Docker 1.7 client against the weave + proxy would report a `no such image` error when the requested image + wasn't present on the Docker host, instead of downloading it. + ## Release 1.0.0 **Highlights**: