fix: when checking for folder existence in container, only pull the

image if not present

works around issue reported in
https://github.com/rancher/k3d/discussions/703 if image is present
locally
pull/679/head
iwilltry42 3 years ago
parent e0f5e2ba2c
commit 9abcbedb37
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 35
      pkg/runtimes/docker/container.go

@ -191,22 +191,31 @@ func executeCheckInContainer(ctx context.Context, image string, cmd []string) (i
}
defer docker.Close()
if err = pullImage(ctx, docker, image); err != nil {
return -1, err
}
resp, err := docker.ContainerCreate(ctx, &container.Config{
Image: image,
Cmd: cmd,
Tty: false,
Entrypoint: []string{},
}, nil, nil, nil, "")
if err != nil {
log.Errorf("Failed to create container from image %s with cmd %s", image, cmd)
return -1, err
// create container
var resp container.ContainerCreateCreatedBody
for {
resp, err = docker.ContainerCreate(ctx, &container.Config{
Image: image,
Cmd: cmd,
Tty: false,
Entrypoint: []string{},
}, nil, nil, nil, "")
if err != nil {
if client.IsErrNotFound(err) {
if err := pullImage(ctx, docker, image); err != nil {
log.Errorf("Failed to create container from image %s with cmd %s", image, cmd)
return -1, err
}
continue
}
log.Errorf("Failed to create container from image %s with cmd %s", image, cmd)
return -1, err
}
break
}
if err = startContainer(ctx, resp.ID); err != nil {
log.Errorf("Failed to start container from image %s with cmd %s", image, cmd)
return -1, err
}

Loading…
Cancel
Save