瀏覽代碼

Merge pull request #2125 from dotcloud/2099_rm-v_fix

- Runtime: fix `docker rm` with volumes
Guillaume J. Charmes 11 年之前
父節點
當前提交
e19cc1e843
共有 2 個文件被更改,包括 42 次插入0 次删除
  1. 3 0
      server.go
  2. 39 0
      server_test.go

+ 3 - 0
server.go

@@ -16,6 +16,7 @@ import (
 	"os"
 	"os"
 	"os/exec"
 	"os/exec"
 	"path"
 	"path"
+	"path/filepath"
 	"runtime"
 	"runtime"
 	"strings"
 	"strings"
 	"sync"
 	"sync"
@@ -958,6 +959,8 @@ func (srv *Server) ContainerDestroy(name string, removeVolume bool) error {
 		volumes := make(map[string]struct{})
 		volumes := make(map[string]struct{})
 		// Store all the deleted containers volumes
 		// Store all the deleted containers volumes
 		for _, volumeId := range container.Volumes {
 		for _, volumeId := range container.Volumes {
+			volumeId = strings.TrimRight(volumeId, "/layer")
+			volumeId = filepath.Base(volumeId)
 			volumes[volumeId] = struct{}{}
 			volumes[volumeId] = struct{}{}
 		}
 		}
 		if err := srv.runtime.Destroy(container); err != nil {
 		if err := srv.runtime.Destroy(container); err != nil {

+ 39 - 0
server_test.go

@@ -108,6 +108,45 @@ func TestCreateRm(t *testing.T) {
 
 
 }
 }
 
 
+func TestCreateRmVolumes(t *testing.T) {
+	runtime := mkRuntime(t)
+	defer nuke(runtime)
+
+	srv := &Server{runtime: runtime}
+
+	config, hostConfig, _, err := ParseRun([]string{"-v", "/srv", GetTestImage(runtime).ID, "echo test"}, nil)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	id, err := srv.ContainerCreate(config)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if len(runtime.List()) != 1 {
+		t.Errorf("Expected 1 container, %v found", len(runtime.List()))
+	}
+
+	err = srv.ContainerStart(id, hostConfig)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	err = srv.ContainerStop(id, 1)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if err = srv.ContainerDestroy(id, true); err != nil {
+		t.Fatal(err)
+	}
+
+	if len(runtime.List()) != 0 {
+		t.Errorf("Expected 0 container, %v found", len(runtime.List()))
+	}
+}
+
 func TestCommit(t *testing.T) {
 func TestCommit(t *testing.T) {
 	runtime := mkRuntime(t)
 	runtime := mkRuntime(t)
 	defer nuke(runtime)
 	defer nuke(runtime)