Browse Source

Detect images/containers conflicts in docker inspect

Victor Vieux 12 years ago
parent
commit
5ec2fea6dd
3 changed files with 13 additions and 1 deletions
  1. 10 0
      api.go
  2. 1 1
      commands.go
  3. 2 0
      docs/sources/api/docker_remote_api_v1.4.rst

+ 10 - 0
api.go

@@ -819,6 +819,11 @@ func getContainersByName(srv *Server, version float64, w http.ResponseWriter, r
 	if err != nil {
 		return err
 	}
+
+	_, err = srv.ImageInspect(name)
+	if err == nil {
+		return fmt.Errorf("Conflict between containers and images")
+	}
 	b, err := json.Marshal(container)
 	if err != nil {
 		return err
@@ -837,6 +842,11 @@ func getImagesByName(srv *Server, version float64, w http.ResponseWriter, r *htt
 	if err != nil {
 		return err
 	}
+
+	_, err = srv.ContainerInspect(name)
+	if err == nil {
+		return fmt.Errorf("Conflict between containers and images")
+	}
 	b, err := json.Marshal(image)
 	if err != nil {
 		return err

+ 1 - 1
commands.go

@@ -577,7 +577,7 @@ func (cli *DockerCli) CmdInspect(args ...string) error {
 		if err != nil {
 			obj, _, err = cli.call("GET", "/images/"+name+"/json", nil)
 			if err != nil {
-				fmt.Fprintf(cli.err, "%s\n", err)
+				fmt.Fprintf(cli.err, "No such image or container: %s\n", name)
 				continue
 			}
 		}

+ 2 - 0
docs/sources/api/docker_remote_api_v1.4.rst

@@ -224,6 +224,7 @@ Inspect a container
 
 	:statuscode 200: no error
 	:statuscode 404: no such container
+	:statuscode 409: conflict between containers and images
 	:statuscode 500: server error
 
 
@@ -760,6 +761,7 @@ Inspect an image
 
 	:statuscode 200: no error
 	:statuscode 404: no such image
+	:statuscode 409: conflict between containers and images
         :statuscode 500: server error