From 49f39736ef60305a565f13563e51314860c9b004 Mon Sep 17 00:00:00 2001 From: Torsten Curdt Date: Thu, 2 Nov 2023 22:35:36 +0100 Subject: [PATCH] more explicit error message for docker buildx context error --- internal/pipe/docker/docker.go | 7 +++++++ www/docs/errors/docker-build.md | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/internal/pipe/docker/docker.go b/internal/pipe/docker/docker.go index fd2d39112e3..01990a37c58 100644 --- a/internal/pipe/docker/docker.go +++ b/internal/pipe/docker/docker.go @@ -235,6 +235,9 @@ files in that dir: Previous error: %w`, tmp, strings.Join(files, "\n "), err) } + if isBuildxContextError(err.Error()) { + return fmt.Errorf(`docker buildx not set to default context\nPlease switch with 'docker context use default'\nLearn more at https://goreleaser.com/errors/docker-build`) + } return err } @@ -262,6 +265,10 @@ func isFileNotFoundError(out string) bool { strings.Contains(out, ": not found") } +func isBuildxContextError(out string) bool { + return strings.Contains(out, "buildx to switch to context") +} + func processImageTemplates(ctx *context.Context, docker config.Docker) ([]string, error) { // nolint:prealloc var images []string diff --git a/www/docs/errors/docker-build.md b/www/docs/errors/docker-build.md index e244a41240e..b5505e4acda 100644 --- a/www/docs/errors/docker-build.md +++ b/www/docs/errors/docker-build.md @@ -17,6 +17,14 @@ its root, so you can just `COPY binaryname /bin/binaryname` and etc. Bellow you can find some **don'ts** as well as what you should **do**. +## `use docker --context=default buildx to switch to context "default"` + +The "default" context is a built-in context in "docker buildx", and it is automatically created. This context typically points to the local Docker environment and is used by default for building images. It has to be active for `goreleaser` to build images with "buildx". + +You can switch to the default context using `docker context use default`. + +This change should be persistant. + ### Don't Build the binary again.