mirror of https://github.com/docker/docs.git
Fix:#748 add refresh container
Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
parent
77884de123
commit
4af3e30f64
|
@ -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
|
// Proxy a request to the right node
|
||||||
func proxyImage(c *context, w http.ResponseWriter, r *http.Request) {
|
func proxyImage(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
name := mux.Vars(r)["name"]
|
name := mux.Vars(r)["name"]
|
||||||
|
|
|
@ -52,14 +52,14 @@ var routes = map[string]map[string]handler{
|
||||||
"/images/{name:.*}/push": proxyImage,
|
"/images/{name:.*}/push": proxyImage,
|
||||||
"/images/{name:.*}/tag": proxyImageAndForceRefresh,
|
"/images/{name:.*}/tag": proxyImageAndForceRefresh,
|
||||||
"/containers/create": postContainersCreate,
|
"/containers/create": postContainersCreate,
|
||||||
"/containers/{name:.*}/kill": proxyContainer,
|
"/containers/{name:.*}/kill": proxyContainerAndForceRefresh,
|
||||||
"/containers/{name:.*}/pause": proxyContainer,
|
"/containers/{name:.*}/pause": proxyContainerAndForceRefresh,
|
||||||
"/containers/{name:.*}/unpause": proxyContainer,
|
"/containers/{name:.*}/unpause": proxyContainerAndForceRefresh,
|
||||||
"/containers/{name:.*}/rename": postRenameContainer,
|
"/containers/{name:.*}/rename": postRenameContainer,
|
||||||
"/containers/{name:.*}/restart": proxyContainer,
|
"/containers/{name:.*}/restart": proxyContainerAndForceRefresh,
|
||||||
"/containers/{name:.*}/start": proxyContainer,
|
"/containers/{name:.*}/start": proxyContainerAndForceRefresh,
|
||||||
"/containers/{name:.*}/stop": proxyContainer,
|
"/containers/{name:.*}/stop": proxyContainerAndForceRefresh,
|
||||||
"/containers/{name:.*}/wait": proxyContainer,
|
"/containers/{name:.*}/wait": proxyContainerAndForceRefresh,
|
||||||
"/containers/{name:.*}/resize": proxyContainer,
|
"/containers/{name:.*}/resize": proxyContainer,
|
||||||
"/containers/{name:.*}/attach": proxyHijack,
|
"/containers/{name:.*}/attach": proxyHijack,
|
||||||
"/containers/{name:.*}/copy": proxyContainer,
|
"/containers/{name:.*}/copy": proxyContainer,
|
||||||
|
|
|
@ -10,3 +10,8 @@ type Container struct {
|
||||||
Info dockerclient.ContainerInfo
|
Info dockerclient.ContainerInfo
|
||||||
Engine *Engine
|
Engine *Engine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refresh container
|
||||||
|
func (c *Container) Refresh() error {
|
||||||
|
return c.Engine.refreshContainer(c.Id, true)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue