diff --git a/internal/stop/stop_test.go b/internal/stop/stop_test.go index e39fdd722b..588e31addf 100644 --- a/internal/stop/stop_test.go +++ b/internal/stop/stop_test.go @@ -163,7 +163,10 @@ func TestStopCommand(t *testing.T) { func TestStopServices(t *testing.T) { t.Run("stops all services", func(t *testing.T) { - containers := []container.Summary{{ID: "c1", State: "running"}, {ID: "c2"}} + containers := []container.Summary{ + {ID: "c1", State: "running"}, + {ID: "c2", State: "exited"}, + } // Setup mock docker require.NoError(t, apitest.MockDocker(utils.Docker)) defer gock.OffAll() @@ -174,6 +177,9 @@ func TestStopServices(t *testing.T) { gock.New(utils.Docker.DaemonHost()). Post("/v" + utils.Docker.ClientVersion() + "/containers/" + containers[0].ID + "/stop"). Reply(http.StatusOK) + gock.New(utils.Docker.DaemonHost()). + Post("/v" + utils.Docker.ClientVersion() + "/containers/" + containers[1].ID + "/stop"). + Reply(http.StatusNotModified) gock.New(utils.Docker.DaemonHost()). Post("/v" + utils.Docker.ClientVersion() + "/containers/prune"). Reply(http.StatusOK). diff --git a/internal/utils/docker.go b/internal/utils/docker.go index 891a5e42dc..9736fa651d 100644 --- a/internal/utils/docker.go +++ b/internal/utils/docker.go @@ -106,12 +106,10 @@ func DockerRemoveAll(ctx context.Context, w io.Writer, projectId string) error { // Gracefully shutdown containers var ids []string for _, c := range containers { - if c.State == "running" { - ids = append(ids, c.ID) - } + ids = append(ids, c.ID) } result := WaitAll(ids, func(id string) error { - if err := Docker.ContainerStop(ctx, id, container.StopOptions{}); err != nil { + if err := Docker.ContainerStop(ctx, id, container.StopOptions{}); err != nil && !errdefs.IsNotModified(err) { return errors.Errorf("failed to stop container: %w", err) } return nil