|
@@ -1257,6 +1257,26 @@ func (srv *Server) ImageDelete(name string, autoPrune bool) ([]APIRmi, error) {
|
|
}
|
|
}
|
|
return nil, nil
|
|
return nil, nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Prevent deletion if image is used by a running container
|
|
|
|
+ for _, container := range srv.runtime.List() {
|
|
|
|
+ if container.State.Running {
|
|
|
|
+ parent, err := srv.runtime.repositories.LookupImage(container.Image)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if err := parent.WalkHistory(func(p *Image) error {
|
|
|
|
+ if img.ID == p.ID {
|
|
|
|
+ return fmt.Errorf("Conflict, cannot delete %s because the running container %s is using it", name, container.ID)
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+ }); err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if strings.Contains(img.ID, name) {
|
|
if strings.Contains(img.ID, name) {
|
|
//delete via ID
|
|
//delete via ID
|
|
return srv.deleteImage(img, "", "")
|
|
return srv.deleteImage(img, "", "")
|