MCPcopy Create free account
hub / github.com/containerd/nerdctl / removeContainers

Method removeContainers

pkg/composer/rm.go:66–97  ·  view source on GitHub ↗
(ctx context.Context, containers []containerd.Container, opt RemoveOptions)

Source from the content-addressed store, hash-verified

64}
65
66func (c *Composer) removeContainers(ctx context.Context, containers []containerd.Container, opt RemoveOptions) error {
67 args := []string{"rm", "-f"}
68 if opt.Volumes {
69 args = append(args, "-v")
70 }
71
72 var rmWG sync.WaitGroup
73 for _, container := range containers {
74 container := container
75 rmWG.Add(1)
76 go func() {
77 defer rmWG.Done()
78 info, _ := container.Info(ctx, containerd.WithoutRefreshedMetadata)
79 // if not `Stop`, check status and skip running container
80 if !opt.Stop {
81 cStatus := formatter.ContainerStatus(ctx, container)
82 if strings.HasPrefix(cStatus, "Up") {
83 log.G(ctx).Warnf("Removing container %s failed: container still running.", info.Labels[labels.Name])
84 return
85 }
86 }
87
88 log.G(ctx).Infof("Removing container %s", info.Labels[labels.Name])
89 if err := c.runNerdctlCmd(ctx, append(args, container.ID())...); err != nil {
90 log.G(ctx).Warn(err)
91 }
92 }()
93 }
94 rmWG.Wait()
95
96 return nil
97}
98
99func (c *Composer) removeContainersFromParsedServices(ctx context.Context, containers map[string]serviceparser.Container) {
100 var rmWG sync.WaitGroup

Callers 4

UpMethod · 0.95
RunMethod · 0.95
RemoveMethod · 0.95
DownMethod · 0.95

Calls 5

runNerdctlCmdMethod · 0.95
ContainerStatusFunction · 0.92
AddMethod · 0.80
InfoMethod · 0.80
WaitMethod · 0.45

Tested by

no test coverage detected