From 5b9d88b3add1e2f2aa8d45afbe2e84dc824cd158 Mon Sep 17 00:00:00 2001 From: l00397676 Date: Thu, 5 Dec 2019 16:23:36 +0800 Subject: [PATCH] docker-container: check local image store if pulling image failed When booting `docker-container` driver, it will pull and run image `moby/buildkit:buildx-stable-1`. If current node cannot connect to dockerhub, driver `docker-container` will always booting failure. But user may already load the image manually or pull it from a priviate registry. Buildx should check local docker image store after pull failed. Fixes: #199 issuecomment-561996661 Signed-off-by: Lu Jingxiao --- driver/docker-container/driver.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/driver/docker-container/driver.go b/driver/docker-container/driver.go index 70f2151f..e9b24dde 100644 --- a/driver/docker-container/driver.go +++ b/driver/docker-container/driver.go @@ -57,7 +57,7 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error { if d.image != "" { imageName = d.image } - env := d.env + if err := l.Wrap("pulling image "+imageName, func() error { rc, err := d.DockerAPI.ImageCreate(ctx, imageName, types.ImageCreateOptions{}) if err != nil { @@ -66,12 +66,18 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error { _, err = io.Copy(ioutil.Discard, rc) return err }); err != nil { - return err + // image pulling failed, check if it exists in local image store. + // if not, return pulling error. otherwise log it. + _, _, errInspect := d.DockerAPI.ImageInspectWithRaw(ctx, imageName) + if errInspect != nil { + return err + } + l.Wrap("pulling failed, using local image "+imageName, func() error { return nil }) } cfg := &container.Config{ Image: imageName, - Env: env, + Env: d.env, } if d.InitConfig.BuildkitFlags != nil { cfg.Cmd = d.InitConfig.BuildkitFlags