MCPcopy
hub / github.com/basecamp/once / removeContainersExcept

Method removeContainersExcept

internal/docker/application.go:399–418  ·  view source on GitHub ↗
(ctx context.Context, keep string)

Source from the content-addressed store, hash-verified

397}
398
399func (a *Application) removeContainersExcept(ctx context.Context, keep string) error {
400 containers, err := a.namespace.client.ContainerList(ctx, container.ListOptions{All: true})
401 if err != nil {
402 return err
403 }
404
405 for _, c := range containers {
406 if len(c.Names) == 0 {
407 continue
408 }
409 name := strings.TrimPrefix(c.Names[0], "/")
410 if a.namespace.containerAppName(name) == a.Settings.Name && name != keep {
411 if err := a.namespace.client.ContainerRemove(ctx, c.ID, container.RemoveOptions{Force: true}); err != nil {
412 return err
413 }
414 }
415 }
416
417 return nil
418}
419
420func (a *Application) volumeMounts(vol *ApplicationVolume) []mount.Mount {
421 var mounts []mount.Mount

Callers 1

deployWithVolumeMethod · 0.95

Calls 2

containerAppNameMethod · 0.80
ContainerListMethod · 0.65

Tested by

no test coverage detected