Skip to content

Commit

Permalink
Fix multiple containers removal issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykiselev committed Dec 27, 2024
1 parent d2b67d5 commit ca36923
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions itests/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,27 @@ func (d *Docker) startNode(
}

func (d *Docker) removeContainers() error {
err := d.pool.RemoveContainerByName(d.suite)
containers, err := d.pool.Client.ListContainers(dc.ListContainersOptions{
All: true,
Filters: map[string][]string{
"name": {d.suite},
},
})
if err != nil {
return errors.Wrapf(err, "failed to remove existing containers for suite %s", d.suite)
return fmt.Errorf("failed to list suite %q containers: %w", d.suite, err)
}
if len(containers) == 0 {
return nil
}
for _, c := range containers {
err = d.pool.Client.RemoveContainer(dc.RemoveContainerOptions{
ID: c.ID,
Force: true,
RemoveVolumes: true,
})
if err != nil {
return fmt.Errorf("failed to remove container %q of suite %q: %w", c.ID, d.suite, err)
}
}
return nil
}
Expand Down

0 comments on commit ca36923

Please sign in to comment.