diff --git a/api/handlers.go b/api/handlers.go index 0322d3f50b..f95937e209 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -532,6 +532,27 @@ func proxyContainer(c *context, w http.ResponseWriter, r *http.Request) { } } +// Proxy a request to the right node and force refresh container +func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Request) { + name, container, err := getContainerFromVars(c, mux.Vars(r)) + if err != nil { + httpError(w, err.Error(), http.StatusNotFound) + return + } + + // Set the full container ID in the proxied URL path. + if name != "" { + r.URL.Path = strings.Replace(r.URL.Path, name, container.Id, 1) + } + + if err := proxy(c.tlsConfig, container.Engine.Addr, w, r); err != nil { + httpError(w, err.Error(), http.StatusInternalServerError) + } + + // force fresh container + container.Refresh() +} + // Proxy a request to the right node func proxyImage(c *context, w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] diff --git a/api/router.go b/api/router.go index fbf95025e0..55d162b0d3 100644 --- a/api/router.go +++ b/api/router.go @@ -52,14 +52,14 @@ var routes = map[string]map[string]handler{ "/images/{name:.*}/push": proxyImage, "/images/{name:.*}/tag": proxyImageAndForceRefresh, "/containers/create": postContainersCreate, - "/containers/{name:.*}/kill": proxyContainer, - "/containers/{name:.*}/pause": proxyContainer, - "/containers/{name:.*}/unpause": proxyContainer, + "/containers/{name:.*}/kill": proxyContainerAndForceRefresh, + "/containers/{name:.*}/pause": proxyContainerAndForceRefresh, + "/containers/{name:.*}/unpause": proxyContainerAndForceRefresh, "/containers/{name:.*}/rename": postRenameContainer, - "/containers/{name:.*}/restart": proxyContainer, - "/containers/{name:.*}/start": proxyContainer, - "/containers/{name:.*}/stop": proxyContainer, - "/containers/{name:.*}/wait": proxyContainer, + "/containers/{name:.*}/restart": proxyContainerAndForceRefresh, + "/containers/{name:.*}/start": proxyContainerAndForceRefresh, + "/containers/{name:.*}/stop": proxyContainerAndForceRefresh, + "/containers/{name:.*}/wait": proxyContainerAndForceRefresh, "/containers/{name:.*}/resize": proxyContainer, "/containers/{name:.*}/attach": proxyHijack, "/containers/{name:.*}/copy": proxyContainer, diff --git a/cluster/container.go b/cluster/container.go index ad8004f912..37407a96a0 100644 --- a/cluster/container.go +++ b/cluster/container.go @@ -10,3 +10,8 @@ type Container struct { Info dockerclient.ContainerInfo Engine *Engine } + +// Refresh container +func (c *Container) Refresh() error { + return c.Engine.refreshContainer(c.Id, true) +}