diff --git a/api.go b/api.go index 621d9c82e1..e6ac49ad28 100644 --- a/api.go +++ b/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/docs/sources/api/docker_remote_api.rst b/docs/sources/api/docker_remote_api.rst index 66e8348e72..5056a62a19 100644 --- a/docs/sources/api/docker_remote_api.rst +++ b/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/server.go b/server.go index 0440b0a8a4..90ec79986c 100644 --- a/server.go +++ b/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