diff --git a/integration/runtime_test.go b/integration/runtime_test.go index 7074a14ce9..016e96d93b 100644 --- a/integration/runtime_test.go +++ b/integration/runtime_test.go @@ -843,3 +843,43 @@ func TestGetAllChildren(t *testing.T) { } } } + +func TestDestroyWithInitLayer(t *testing.T) { + runtime := mkRuntime(t) + defer nuke(runtime) + + container, _, err := runtime.Create(&docker.Config{ + Image: GetTestImage(runtime).ID, + Cmd: []string{"ls", "-al"}, + }, "") + + if err != nil { + t.Fatal(err) + } + // Destroy + if err := runtime.Destroy(container); err != nil { + t.Fatal(err) + } + + // Make sure runtime.Exists() behaves correctly + if runtime.Exists("test_destroy") { + t.Fatalf("Exists() returned true") + } + + // Make sure runtime.List() doesn't list the destroyed container + if len(runtime.List()) != 0 { + t.Fatalf("Expected 0 container, %v found", len(runtime.List())) + } + + driver := runtime.Graph().Driver() + + // Make sure that the container does not exist in the driver + if _, err := driver.Get(container.ID); err == nil { + t.Fatal("Conttainer should not exist in the driver") + } + + // Make sure that the init layer is removed from the driver + if _, err := driver.Get(fmt.Sprintf("%s-init", container.ID)); err == nil { + t.Fatal("Container's init layer should not exist in the driver") + } +} diff --git a/runtime.go b/runtime.go index a7c2659b00..2e2492a6e1 100644 --- a/runtime.go +++ b/runtime.go @@ -237,6 +237,11 @@ func (runtime *Runtime) Destroy(container *Container) error { return fmt.Errorf("Driver %s failed to remove root filesystem %s: %s", runtime.driver, container.ID, err) } + initID := fmt.Sprintf("%s-init", container.ID) + if err := runtime.driver.Remove(initID); err != nil { + return fmt.Errorf("Driver %s failed to remove init filesystem %s: %s", runtime.driver, initID, err) + } + if _, err := runtime.containerGraph.Purge(container.ID); err != nil { utils.Debugf("Unable to remove container from link graph: %s", err) }