diff --git a/pkg/skaffold/docker/image.go b/pkg/skaffold/docker/image.go index 542fd021e6c..ba4a2e89c70 100644 --- a/pkg/skaffold/docker/image.go +++ b/pkg/skaffold/docker/image.go @@ -24,10 +24,12 @@ import ( "sort" "strings" "sync" + "time" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/mount" "github.com/docker/docker/client" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/progress" "github.com/docker/docker/pkg/streamformatter" @@ -39,6 +41,11 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) +const ( + retries = 5 + sleepTime = 1 * time.Second +) + type ContainerRun struct { Image string User string @@ -384,7 +391,17 @@ func (l *localDaemon) ImageInspectWithRaw(ctx context.Context, image string) (ty } func (l *localDaemon) ImageRemove(ctx context.Context, image string, opts types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) { - return l.apiClient.ImageRemove(ctx, image, opts) + for i := 0; i < retries; i++ { + resp, err := l.apiClient.ImageRemove(ctx, image, opts) + if err == nil { + return resp, nil + } + if _, ok := err.(errdefs.ErrConflict); !ok { + return nil, err + } + time.Sleep(sleepTime) + } + return nil, fmt.Errorf("could not remove image after %d retries", retries) } // GetBuildArgs gives the build args flags for docker build.