Fix issue `docker compose rm -s` not removing containers

Signed-off-by: Hironao OTSUBO <motemen@gmail.com>
This commit is contained in:
Hironao OTSUBO 2021-07-29 23:37:13 +09:00
parent 7b03b04484
commit 1a0efdd413
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")
})
}