From 3efe0a345bd320feb4db0f13e5f8b44b1bbcea25 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 31 May 2013 15:34:23 +0000 Subject: [PATCH] returns an error if the container we want to attach is not running Upstream-commit: 468e4c4b565d25b03c68ce2ab31f9a52f7b3398a Component: engine --- components/engine/api.go | 2 ++ components/engine/docs/sources/api/docker_remote_api.rst | 1 + components/engine/server.go | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/engine/api.go b/components/engine/api.go index 621d9c82e1..e6ac49ad28 100644 --- a/components/engine/api.go +++ b/components/engine/api.go @@ -45,6 +45,8 @@ func httpError(w http.ResponseWriter, err error) { http.Error(w, err.Error(), http.StatusNotFound) } else if strings.HasPrefix(err.Error(), "Bad parameter") { http.Error(w, err.Error(), http.StatusBadRequest) + } else if strings.HasPrefix(err.Error(), "Impossible") { + http.Error(w, err.Error(), http.StatusNotAcceptable) } else { http.Error(w, err.Error(), http.StatusInternalServerError) } diff --git a/components/engine/docs/sources/api/docker_remote_api.rst b/components/engine/docs/sources/api/docker_remote_api.rst index bd87dc7a03..98b0005cda 100644 --- a/components/engine/docs/sources/api/docker_remote_api.rst +++ b/components/engine/docs/sources/api/docker_remote_api.rst @@ -132,6 +132,7 @@ Create a container :jsonparam config: the container's configuration :statuscode 201: no error :statuscode 404: no such container + :statuscode 406: impossible to attach (container not running) :statuscode 500: server error diff --git a/components/engine/server.go b/components/engine/server.go index 0440b0a8a4..90ec79986c 100644 --- a/components/engine/server.go +++ b/components/engine/server.go @@ -790,7 +790,6 @@ func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, std if container == nil { return fmt.Errorf("No such container: %s", name) } - //logs if logs { if stdout { @@ -816,6 +815,9 @@ func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, std if container.State.Ghost { return fmt.Errorf("Impossible to attach to a ghost container") } + if !container.State.Running { + return fmt.Errorf("Impossible to attach to a stopped container, start it first") + } var ( cStdin io.ReadCloser