Преглед на файлове

Merge pull request #766 from dotcloud/prevent_attach_stopped_container-feature

returns an error if the container we want to attach is not running
Guillaume J. Charmes преди 12 години
родител
ревизия
7d167590bc
променени са 3 файла, в които са добавени 6 реда и са изтрити 1 реда
  1. 2 0
      api.go
  2. 1 0
      docs/sources/api/docker_remote_api.rst
  3. 3 1
      server.go

+ 2 - 0
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)
 	}

+ 1 - 0
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
 
 

+ 3 - 1
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