Merge pull request #1965 from motemen/fix-rm-stop

Fix issue `docker compose rm -s` not removing containers
This commit is contained in:
Mathieu Champlon 2021-07-30 08:37:54 +02:00 committed by GitHub
commit 377493d473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -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{

View File

@ -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")
})
}