1
0
Fork 0
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:
Sebastiaan van Stijn 2016-11-09 15:44:33 +01:00 committed by GitHub
commit 70b53c932d

View file

@ -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)