mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #28141 from darrenstahlmsft/TerminateTemplates
Terminate template containers before delting a layer
This commit is contained in:
commit
70b53c932d
1 changed files with 26 additions and 0 deletions
|
@ -244,6 +244,32 @@ func (d *Driver) Remove(id string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Get and terminate any template VMs that are currently using the layer
|
||||
computeSystems, err := hcsshim.GetContainers(hcsshim.ComputeSystemQuery{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, computeSystem := range computeSystems {
|
||||
if strings.Contains(computeSystem.RuntimeImagePath, id) && computeSystem.IsRuntimeTemplate {
|
||||
container, err := hcsshim.OpenContainer(computeSystem.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer container.Close()
|
||||
err = container.Terminate()
|
||||
if hcsshim.IsPending(err) {
|
||||
err = container.Wait()
|
||||
} else if hcsshim.IsAlreadyStopped(err) {
|
||||
err = nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layerPath := filepath.Join(d.info.HomeDir, rID)
|
||||
tmpID := fmt.Sprintf("%s-removing", rID)
|
||||
tmpLayerPath := filepath.Join(d.info.HomeDir, tmpID)
|
||||
|
|
Loading…
Add table
Reference in a new issue