mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #3144 from codeaholics/643-stale-nfs-handle
Prevent deletion of image if ANY container is depending on it; not just running containers
This commit is contained in:
commit
1124261158
1 changed files with 11 additions and 13 deletions
24
server.go
24
server.go
|
@ -1561,22 +1561,20 @@ func (srv *Server) ImageDelete(name string, autoPrune bool) ([]APIRmi, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
// Prevent deletion if image is used by a running container
|
||||
// Prevent deletion if image is used by a container
|
||||
for _, container := range srv.runtime.List() {
|
||||
if container.State.IsRunning() {
|
||||
parent, err := srv.runtime.repositories.LookupImage(container.Image)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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 err := parent.WalkHistory(func(p *Image) error {
|
||||
if img.ID == p.ID {
|
||||
return fmt.Errorf("Conflict, cannot delete %s because the container %s is using it", name, container.ID)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue