Skip to content

Commit f7eb4b8

Browse files
committed
fix(standalone): fall back to local image when registry pull fails
Signed-off-by: Dorin Geman <dorin.geman@docker.com>
1 parent b96b66b commit f7eb4b8

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

cmd/cli/pkg/standalone/images.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,30 @@ import (
99
"github.com/moby/moby/client/pkg/jsonmessage"
1010
)
1111

12-
// EnsureControllerImage ensures that the controller container image is pulled.
12+
// EnsureControllerImage ensures that the controller container image is
13+
// available. It first tries to pull from the registry; if that fails it
14+
// falls back to a locally available image with the same name.
1315
func EnsureControllerImage(ctx context.Context, dockerClient client.ImageAPIClient, gpu gpupkg.GPUSupport, backend string, printer StatusPrinter) error {
1416
imageName := controllerImageName(gpu, backend)
1517

16-
// Perform the pull.
17-
out, err := dockerClient.ImagePull(ctx, imageName, client.ImagePullOptions{})
18-
if err != nil {
19-
return fmt.Errorf("failed to pull image %s: %w", imageName, err)
18+
var pullErr error
19+
out, pullErr := dockerClient.ImagePull(ctx, imageName, client.ImagePullOptions{})
20+
if pullErr == nil {
21+
defer out.Close()
22+
fd, isTerminal := printer.GetFdInfo()
23+
pullErr = jsonmessage.DisplayJSONMessagesStream(out, printer, fd, isTerminal, nil)
2024
}
21-
defer out.Close()
22-
23-
// Display pull progress using Docker's built-in display handler
24-
fd, isTerminal := printer.GetFdInfo()
25-
if err := jsonmessage.DisplayJSONMessagesStream(out, printer, fd, isTerminal, nil); err != nil {
26-
return fmt.Errorf("failed to pull image %s: %w", imageName, err)
25+
if pullErr == nil {
26+
printer.Println("Successfully pulled", imageName)
27+
return nil
2728
}
2829

29-
printer.Println("Successfully pulled", imageName)
30+
// Pull failed — check if the image exists locally.
31+
_, inspectErr := dockerClient.ImageInspect(ctx, imageName)
32+
if inspectErr != nil {
33+
return fmt.Errorf("failed to pull image %s and no local image found: %w", imageName, pullErr)
34+
}
35+
printer.Println("Using local image", imageName)
3036
return nil
3137
}
3238

0 commit comments

Comments
 (0)