diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2017-11-29 00:05:23 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-11-29 12:15:16 +0000 |
commit | ce3081786b6573abad764ac425fb9b7c5b74c465 (patch) | |
tree | 963688c283f3ba7bdbfeb3961313b638fe8aac45 /libpod/runtime_img.go | |
parent | 4a68a5303c74298f50c4a2d51e75527d439f09f1 (diff) | |
download | podman-ce3081786b6573abad764ac425fb9b7c5b74c465.tar.gz podman-ce3081786b6573abad764ac425fb9b7c5b74c465.tar.bz2 podman-ce3081786b6573abad764ac425fb9b7c5b74c465.zip |
Fix rmi -f removing containers from storage without telling libpod
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #68
Approved by: rhatdan
Diffstat (limited to 'libpod/runtime_img.go')
-rw-r--r-- | libpod/runtime_img.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go index 2b18a5322..ba1cec96f 100644 --- a/libpod/runtime_img.go +++ b/libpod/runtime_img.go @@ -798,19 +798,26 @@ func (r *Runtime) RemoveImage(image *storage.Image, force bool) (string, error) return "", ErrRuntimeStopped } - containersWithImage, err := r.getContainersWithImage(image.ID) + // Get all containers, filter to only those using the image, and remove those containers + ctrs, err := r.state.AllContainers() if err != nil { - return "", errors.Wrapf(err, "error getting containers for image %q", image.ID) + return "", err + } + imageCtrs := []*Container{} + for _, ctr := range ctrs { + if ctr.config.RootfsImageID == image.ID { + imageCtrs = append(imageCtrs, ctr) + } } - if len(containersWithImage) > 0 && len(image.Names) <= 1 { + if len(imageCtrs) > 0 && len(image.Names) <= 1 { if force { - if err := r.removeMultipleContainers(containersWithImage); err != nil { - return "", err + for _, ctr := range imageCtrs { + if err := r.removeContainer(ctr, true); err != nil { + return "", errors.Wrapf(err, "error removing image %s: container %s using image could not be removed", image.ID, ctr.ID()) + } } } else { - for _, ctr := range containersWithImage { - return "", fmt.Errorf("Could not remove image %q (must force) - container %q is using its reference image", image.ID, ctr.ImageID) - } + return "", fmt.Errorf("could not remove image %s as it is being used by %d containers", image.ID, len(imageCtrs)) } } |