Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker build failed: exit status 1: ERROR: use docker --context=default buildx to switch to context "default" #4392

Closed
3 of 4 tasks
koddr opened this issue Oct 31, 2023 · 15 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@koddr
Copy link
Contributor

koddr commented Oct 31, 2023

What happened?

When I run goreleaser release, the process reaches the section with Docker image creation and an error appears:

docker build failed: failed to build gowebly/gowebly:latest-arm64: exit status 1: ERROR: use `docker --context=default buildx` to switch to context "default"

My .goreleaser.yml:

...

dockers:
  -
    id: '{{ .ProjectName }}_linux_amd64' # For GNU/Linux x86_64
    ids: [ default ]
    use: buildx
    skip_push: auto
    image_templates:
      - 'gowebly/{{ .ProjectName }}:latest-linux-amd64'
      - 'gowebly/{{ .ProjectName }}:{{ .Tag }}-linux-amd64'
    build_flag_templates:
      - '--pull'
      - '--label=org.opencontainers.image.created={{ .Date }}'
      - '--label=org.opencontainers.image.title={{ .ProjectName }}'
      - '--label=org.opencontainers.image.revision={{ .FullCommit }}'
      - '--label=org.opencontainers.image.version={{ .Version }}'
      - '--platform=linux/amd64'
    push_flags:
      - '--tls-verify=false'
  -
    id: '{{ .ProjectName }}_linux_arm64' # For GNU/Linux ARM
    ids: [ default ]
    use: buildx
    skip_push: auto
    image_templates:
      - 'gowebly/{{ .ProjectName }}:latest-linux-arm64'
      - 'gowebly/{{ .ProjectName }}:{{ .Tag }}-linux-arm64'
    build_flag_templates:
      - '--pull'
      - '--label=org.opencontainers.image.created={{ .Date }}'
      - '--label=org.opencontainers.image.title={{ .ProjectName }}'
      - '--label=org.opencontainers.image.revision={{ .FullCommit }}'
      - '--label=org.opencontainers.image.version={{ .Version }}'
      - '--platform=linux/arm64'
    push_flags:
      - '--tls-verify=false'
  -
    id: '{{ .ProjectName }}_darwin_amd64' # For Apple macOS x86_64
    ids: [ default ]
    use: buildx
    skip_push: auto
    image_templates:
      - 'gowebly/{{ .ProjectName }}:latest-darwin-amd64'
      - 'gowebly/{{ .ProjectName }}:{{ .Tag }}-darwin-amd64'
    build_flag_templates:
      - '--pull'
      - '--label=org.opencontainers.image.created={{ .Date }}'
      - '--label=org.opencontainers.image.title={{ .ProjectName }}'
      - '--label=org.opencontainers.image.revision={{ .FullCommit }}'
      - '--label=org.opencontainers.image.version={{ .Version }}'
      - '--platform=darwin/amd64'
    push_flags:
      - '--tls-verify=false'
  -
    id: '{{ .ProjectName }}_darwin_arm64' # For Apple macOS ARM
    ids: [ default ]
    use: buildx
    skip_push: auto
    image_templates:
      - 'gowebly/{{ .ProjectName }}:latest-darwin-arm64'
      - 'gowebly/{{ .ProjectName }}:{{ .Tag }}-darwin-arm64'
    build_flag_templates:
      - '--pull'
      - '--label=org.opencontainers.image.created={{ .Date }}'
      - '--label=org.opencontainers.image.title={{ .ProjectName }}'
      - '--label=org.opencontainers.image.revision={{ .FullCommit }}'
      - '--label=org.opencontainers.image.version={{ .Version }}'
      - '--platform=darwin/arm64'
    push_flags:
      - '--tls-verify=false'

docker_manifests:
  -
    name_template: 'gowebly/{{ .ProjectName }}:latest'
    skip_push: auto
    image_templates:
      - 'gowebly/{{ .ProjectName }}:latest-linux-amd64'
      - 'gowebly/{{ .ProjectName }}:latest-linux-arm64'
      - 'gowebly/{{ .ProjectName }}:latest-darwin-amd64'
      - 'gowebly/{{ .ProjectName }}:latest-darwin-arm64'
  -
    name_template: 'gowebly/{{ .ProjectName }}:{{ .Tag }}'
    skip_push: auto
    image_templates:
      - 'gowebly/{{ .ProjectName }}:{{ .Tag }}-linux-amd64'
      - 'gowebly/{{ .ProjectName }}:{{ .Tag }}-linux-arm64'
      - 'gowebly/{{ .ProjectName }}:{{ .Tag }}-darwin-amd64'
      - 'gowebly/{{ .ProjectName }}:{{ .Tag }}-darwin-arm64'

...

How can we reproduce this?

  1. Clone project https://github.com/gowebly/gowebly
  2. Run goreleaser release
  3. See error

goreleaser version

GitVersion:    1.21.2
GitCommit:     26fed97a0defe4e73e3094cb903225d5445e5f0d
GitTreeState:  false
BuildDate:     2023-09-26T11:20:15Z
BuiltBy:       goreleaser
GoVersion:     go1.21.1
Compiler:      gc
ModuleSum:     h1:dgYtIS7aZlQuRMUMLCjDCOs4lWss85Oh60RDSO0rbWU=
Platform:      darwin/arm64

GoReleaser Check

  • goreleaser check shows no errors

Search

  • I did search for other open and closed issues before opening this

Supporter

Code of Conduct

  • I agree to follow this project's Code of Conduct

Additional context

$ docker-buildx version

github.com/docker/buildx v0.11.2 9872040b6626fb7d87ef7296fd5b832e8cc2ad17
@koddr koddr added bug Something isn't working triage Issue pending triage by one of the maintainers labels Oct 31, 2023
@caarlos0
Copy link
Member

could you paste the output of docker buildx ls?

@koddr
Copy link
Contributor Author

koddr commented Oct 31, 2023

Hmmm...

ERROR: open /Users/user/.docker/buildx/activity/desktop-linux: permission denied

@caarlos0 what I miss?

EDIT:

Okay, I fixed this error by following this comment: https://stackoverflow.com/questions/75686903/open-users-user-docker-buildx-current-permission-denied-on-macbook

The ouput of docker buildx ls is now:

NAME/NODE     DRIVER/ENDPOINT STATUS  BUILDKIT        PLATFORMS
colima *      docker                                  
colima         colima          running v0.10.6+d52b2d5 linux/arm64, linux/amd64, linux/amd64/v2
default                       error                   
desktop-linux                 error                   

Cannot load builder default: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot load builder desktop-linux: Cannot connect to the Docker daemon at unix:///Users/viktorsostak/.docker/run/docker.sock. Is the docker daemon running?

I use colima with a standard Docker installation by brew install.

@tcurdt
Copy link
Contributor

tcurdt commented Nov 1, 2023

I just ran into the same/similar error:

goreleaser release --skip=publish --skip=validate --clean
...
release failed after 1s
error=docker build failed: failed to build tcurdt/foo:latest:
exit status 1:
ERROR: use `docker --context=default buildx` to switch to context "default"

This is the config:

dockers:
  - image_templates:
    - "tcurdt/{{ .ProjectName }}:latest"
    - "tcurdt/{{ .ProjectName }}:v{{ .Version }}"
    - "tcurdt/{{ .ProjectName }}:v{{ .Major }}"
    build_flag_templates:
    - "--label=sha={{.FullCommit}}"
    - "--label=org.opencontainers.image.created={{.Date}}"
    - "--label=org.opencontainers.image.title={{.ProjectName}}"
    - "--label=org.opencontainers.image.revision={{.FullCommit}}"
    - "--label=org.opencontainers.image.version={{.Version}}"
    - "--pull"
    - "--platform=linux/amd64"
    use: buildx

But I my buildx ls does work

$ docker buildx ls
NAME/NODE       DRIVER/ENDPOINT STATUS  BUILDKIT             PLATFORMS
default         docker                                       
  default       default         running v0.11.6+616c3f613b54 linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
desktop-linux * docker                                       
  desktop-linux desktop-linux   running v0.11.6+616c3f613b54 linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6

@caarlos0
Copy link
Member

caarlos0 commented Nov 1, 2023

I think that if you could add --context=<the context name> to build_flag_templates it would work, but we probably need a better solution

@tcurdt
Copy link
Contributor

tcurdt commented Nov 1, 2023

goreleaser release --skip=publish --skip=validate --clean

Unfortunately that seems to end up in the wrong place. What I get is

error=docker build failed: failed to build tcurdt/foo:latest: exit status 125: unknown flag: --context

It seems it has to come before buildx.

@caarlos0
Copy link
Member

caarlos0 commented Nov 1, 2023

ah, correct... okay, so we'll need to fix this in another way, will take a proper look later

@caarlos0 caarlos0 removed the triage Issue pending triage by one of the maintainers label Nov 1, 2023
@dunglas
Copy link
Contributor

dunglas commented Nov 2, 2023

Or just run docker context use default before running GoReleaser.

@tcurdt
Copy link
Contributor

tcurdt commented Nov 2, 2023

@dunglas That would be too easy! (embarrassed sarcasm)

Thanks :)

If the switch is persistent maybe there isn't much to do in code really.

@caarlos0
Copy link
Member

caarlos0 commented Nov 2, 2023

maybe we could at least document this better though... if anyone wants to give a swing at PR-ing that :D

@tcurdt
Copy link
Contributor

tcurdt commented Nov 2, 2023

We could search for "to switch to context" in the error message and output some more information right from goreleaser. Or would you rather see it in the docs/FAQ or something, @caarlos0 ?

@caarlos0
Copy link
Member

caarlos0 commented Nov 2, 2023

I think we could yeah, maybe search for that, and thrown an error with an URL pointing to a better explanation, like this one for example: https://goreleaser.com/errors/dirty/

@caarlos0
Copy link
Member

caarlos0 commented Nov 4, 2023

fixed in #4401, thanks @tcurdt !

@caarlos0 caarlos0 closed this as completed Nov 4, 2023
@caarlos0 caarlos0 added this to the v1.22.0 milestone Nov 4, 2023
@jimschubert
Copy link

I recently upgraded from goreleaser 1.14 and had this issue when using buildx. I wasn't able to get the build to work with other workarounds in this thread, so I thought I'd comment my solution here for others who find this issue.

First, I had to modify the option in Docker Desktop for "Allow the default Docker socket to be used".

image

The problem was that, for security, I had previously had my default docker and buildx context set to desktop-linux. I don't recall if I had run goreleaser locally at any point after making that change, as I usually rely on CI to check the cross-platform builds.

I thought I should be able to change the "default" buildx context to the desktop-linux context which points to unix:///Users/jim/.docker/run/docker.sock on my machine, but I couldn't figure how to get buildx to use the custom context as default. After following the docker context use default workaround from this thread, I had this error:

$ docker buildx use desktop-linux --default
ERROR: run `docker context use desktop-linux` to switch to context desktop-linux

Running docker context use desktop-linux followed by either docker buildx use desktop-linux or docker buildx use desktop-linux --default allows me to set the buildx context back to my intended "default" but goreleaser still fails. The --default here doesn't change the context's name.

I think goreleaser would need to be updated to allow customization of the context which is defined as default here:

base = []string{"buildx", "--builder", "default", "build", ".", "--load"}

To get back into a good state for goreleaser with buildx, I had to run both of these after allowing user access to the default socket:

docker context use default
docker buildx use default --default

Here's my version information for reference:

$ goreleaser --version
  ____       ____      _                            ____
 / ___| ___ |  _ \ ___| | ___  __ _ ___  ___ _ __  |  _ \ _ __ ___
| |  _ / _ \| |_) / _ \ |/ _ \/ _` / __|/ _ \ '__| | |_) | '__/ _ \
| |_| | (_) |  _ <  __/ |  __/ (_| \__ \  __/ |    |  __/| | | (_) |
 \____|\___/|_| \_\___|_|\___|\__,_|___/\___|_|    |_|   |_|  \___/
goreleaser-pro: Deliver Go Binaries as fast and easily as possible
https://goreleaser.com/pro

GitVersion:    1.23.0-pro
GitCommit:     3973205d96767d1f1b0d378584a75697cad58444
GitTreeState:  clean
BuildDate:     2023-12-26T15:04:19Z
BuiltBy:       goreleaser
GoVersion:     go1.21.5
Compiler:      gc
ModuleSum:     unknown
Platform:      darwin/amd64

$ docker version
Client:
 Cloud integration: v1.0.35+desktop.5
 Version:           24.0.6
 API version:       1.43
 Go version:        go1.20.7
 Git commit:        ed223bc
 Built:             Mon Sep  4 12:28:49 2023
 OS/Arch:           darwin/amd64
 Context:           default

Server: Docker Desktop 4.24.2 (124339)
 Engine:
  Version:          24.0.6
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.7
  Git commit:       1a79695
  Built:            Mon Sep  4 12:32:16 2023
  OS/Arch:          linux/amd64
  Experimental:     true
 containerd:
  Version:          1.6.22
  GitCommit:        8165feabfdfe38c65b599c4993d227328c231fca
 runc:
  Version:          1.1.8
  GitCommit:        v1.1.8-0-g82f18fe
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

@davidolrik
Copy link

I think goreleaser would need to be updated to allow customization of the context which is defined as default here:

base = []string{"buildx", "--builder", "default", "build", ".", "--load"}

I would tend to agree here, there is no reason to force the use of the default context.

According to the docs, the --builder option is for overriding, so it should be ok to leave it out.

Options:
      --builder string   Override the configured builder instance

With that in mind I tried removing --builder default from api_docker.go and did a test release using goreleaser with my context set to colima:

$ docker context ls
NAME       DESCRIPTION                               DOCKER ENDPOINT                                 ERROR
colima *   colima                                    unix:///Users/me/.colima/default/docker.sock
default    Current DOCKER_HOST based configuration   unix:///var/run/docker.sock

$ docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS  BUILDKIT             PLATFORMS
colima *  docker
  colima  colima          running v0.11.7+d3e6c1360f6e linux/arm64, linux/amd64, linux/amd64/v2
default                   error

Cannot load builder default: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

And it works just fine =)

caarlos0 added a commit that referenced this issue Jan 22, 2024
refs #4392

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
@caarlos0
Copy link
Member

caarlos0 commented Jan 22, 2024

I think I agree, playing with it in #4566

caarlos0 added a commit that referenced this issue Jan 22, 2024
…dx (#4566)

refs #4392

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants