Remove removes stopped containers in `services`.
(ctx context.Context, opt RemoveOptions, services []string)
| 40 | |
| 41 | // Remove removes stopped containers in `services`. |
| 42 | func (c *Composer) Remove(ctx context.Context, opt RemoveOptions, services []string) error { |
| 43 | serviceNames, err := c.ServiceNames(services...) |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | // reverse dependency order |
| 48 | for _, svc := range strutil.ReverseStrSlice(serviceNames) { |
| 49 | containers, err := c.Containers(ctx, svc) |
| 50 | if err != nil { |
| 51 | return err |
| 52 | } |
| 53 | if opt.Stop { |
| 54 | // use default Options to stop service containers. |
| 55 | if err := c.stopContainers(ctx, containers, StopOptions{}); err != nil { |
| 56 | return err |
| 57 | } |
| 58 | } |
| 59 | if err := c.removeContainers(ctx, containers, opt); err != nil { |
| 60 | return err |
| 61 | } |
| 62 | } |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | func (c *Composer) removeContainers(ctx context.Context, containers []containerd.Container, opt RemoveOptions) error { |
| 67 | args := []string{"rm", "-f"} |
nothing calls this directly
no test coverage detected