Browse Source

Merge pull request #13527 from duglin/FixImagesPrefixNotFound

Fix error when trying to delete an image due to a bad container
Jessie Frazelle 10 years ago
parent
commit
a39de41871
1 changed files with 11 additions and 0 deletions
  1. 11 0
      daemon/image_delete.go

+ 11 - 0
daemon/image_delete.go

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