mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix error when trying to delete an image due to a bad container
I ran into a situation where I was trying: `docker rmi busybox` and it kept failing saying: `could not find image: Prefix can't be empty` While I have no idea how I got into this situation, it turns out this is error message is from `daemon.canDeleteImage()`. In that func we loop over all containers checking to see if they're using the image we're trying to delete. In my case though, I had a container with no ImageID. So the code would die tryig to find that image (hence the "Prefix can't be empty" err). This would stop all processing despite the fact that the container we're checking had nothing to do with 'busybox'. My change logs the bad situation in the logs and then skips that container. There's no reason to fail all `docker rmi ...` calls just because of one bad container. Will continue to try to figure out how I got a container w/o an ImageID but as of now I have no idea, I didn't do anything but normal docker cli commands. Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
parent
7b57fae046
commit
71a4990229
1 changed files with 11 additions and 0 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/graph"
|
"github.com/docker/docker/graph"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
|
@ -140,6 +141,16 @@ func (daemon *Daemon) imgDeleteHelper(name string, list *[]types.ImageDelete, fi
|
||||||
|
|
||||||
func (daemon *Daemon) canDeleteImage(imgID string, force bool) error {
|
func (daemon *Daemon) canDeleteImage(imgID string, force bool) error {
|
||||||
for _, container := range daemon.List() {
|
for _, container := range daemon.List() {
|
||||||
|
if container.ImageID == "" {
|
||||||
|
// This technically should never happen, but if the container
|
||||||
|
// has no ImageID then log the situation and move on.
|
||||||
|
// If we allowed processing to continue then the code later
|
||||||
|
// on would fail with a "Prefix can't be empty" error even
|
||||||
|
// though the bad container has nothing to do with the image
|
||||||
|
// we're trying to delete.
|
||||||
|
logrus.Errorf("Container %q has no image associated with it!", container.ID)
|
||||||
|
continue
|
||||||
|
}
|
||||||
parent, err := daemon.Repositories().LookupImage(container.ImageID)
|
parent, err := daemon.Repositories().LookupImage(container.ImageID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if daemon.Graph().IsNotExist(err, container.ImageID) {
|
if daemon.Graph().IsNotExist(err, container.ImageID) {
|
||||||
|
|
Loading…
Reference in a new issue