From 1a0efdd413423e9c6fc7a7dfb63c0e5fb2767e1a Mon Sep 17 00:00:00 2001 From: Hironao OTSUBO Date: Thu, 29 Jul 2021 23:37:13 +0900 Subject: [PATCH] Fix issue `docker compose rm -s` not removing containers Signed-off-by: Hironao OTSUBO --- cmd/compose/remove.go | 5 ++++- pkg/e2e/compose_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cmd/compose/remove.go b/cmd/compose/remove.go index 924cdab23..5d41f7284 100644 --- a/cmd/compose/remove.go +++ b/cmd/compose/remove.go @@ -65,9 +65,12 @@ func runRemove(ctx context.Context, backend api.Service, opts removeOptions, ser } if opts.stop { - return backend.Stop(ctx, project, api.StopOptions{ + err := backend.Stop(ctx, project, api.StopOptions{ Services: services, }) + if err != nil { + return err + } } return backend.Remove(ctx, project, api.RemoveOptions{ diff --git a/pkg/e2e/compose_test.go b/pkg/e2e/compose_test.go index 25405d65d..7454a237a 100644 --- a/pkg/e2e/compose_test.go +++ b/pkg/e2e/compose_test.go @@ -171,3 +171,27 @@ func TestInitContainer(t *testing.T) { defer c.RunDockerOrExitError("compose", "-p", "init-container", "down") testify.Regexp(t, "foo_1 | hello(?m:.*)bar_1 | world", res.Stdout()) } + +func TestRm(t *testing.T) { + c := NewParallelE2eCLI(t, binDir) + + const projectName = "compose-e2e-rm" + + t.Run("up", func(t *testing.T) { + c.RunDockerCmd("compose", "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "up", "-d") + }) + + t.Run("rm -sf", func(t *testing.T) { + res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "rm", "-sf", "simple") + res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0}) + }) + + t.Run("check containers after rm -sf", func(t *testing.T) { + res := c.RunDockerCmd("ps", "--all") + assert.Assert(t, !strings.Contains(res.Combined(), projectName+"_simple"), res.Combined()) + }) + + t.Run("down", func(t *testing.T) { + c.RunDockerCmd("compose", "-p", projectName, "down") + }) +}