Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 377493d

Browse files
authored
Merge pull request #1965 from motemen/fix-rm-stop
Fix issue `docker compose rm -s` not removing containers
2 parents 7b03b04 + 1a0efdd commit 377493d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

cmd/compose/remove.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ func runRemove(ctx context.Context, backend api.Service, opts removeOptions, ser
6565
}
6666

6767
if opts.stop {
68-
return backend.Stop(ctx, project, api.StopOptions{
68+
err := backend.Stop(ctx, project, api.StopOptions{
6969
Services: services,
7070
})
71+
if err != nil {
72+
return err
73+
}
7174
}
7275

7376
return backend.Remove(ctx, project, api.RemoveOptions{

pkg/e2e/compose_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,27 @@ func TestInitContainer(t *testing.T) {
171171
defer c.RunDockerOrExitError("compose", "-p", "init-container", "down")
172172
testify.Regexp(t, "foo_1 | hello(?m:.*)bar_1 | world", res.Stdout())
173173
}
174+
175+
func TestRm(t *testing.T) {
176+
c := NewParallelE2eCLI(t, binDir)
177+
178+
const projectName = "compose-e2e-rm"
179+
180+
t.Run("up", func(t *testing.T) {
181+
c.RunDockerCmd("compose", "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "up", "-d")
182+
})
183+
184+
t.Run("rm -sf", func(t *testing.T) {
185+
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-composefile/compose.yaml", "-p", projectName, "rm", "-sf", "simple")
186+
res.Assert(t, icmd.Expected{Err: "Removed", ExitCode: 0})
187+
})
188+
189+
t.Run("check containers after rm -sf", func(t *testing.T) {
190+
res := c.RunDockerCmd("ps", "--all")
191+
assert.Assert(t, !strings.Contains(res.Combined(), projectName+"_simple"), res.Combined())
192+
})
193+
194+
t.Run("down", func(t *testing.T) {
195+
c.RunDockerCmd("compose", "-p", projectName, "down")
196+
})
197+
}

0 commit comments

Comments
 (0)