github.com/goreleaser/goreleaser@v1.25.1/www/docs/errors/docker-build.md (about) 1 # Docker build failures 2 3 ## `COPY failed: file not found in build context` 4 5 This usually happens when trying to build the binary again from source code in 6 the Docker image build process. 7 8 The way GoReleaser works, the correct binary for the platform you're building 9 should be already available, so you don't need to build it again and can still 10 reuse the `Dockefile`. 11 12 Another common misconception is trying to copy the binary as if the context is 13 the repository root. 14 It's not. 15 It's always a new temporary build context with the artifacts you can use in 16 its root, so you can just `COPY binaryname /bin/binaryname` and etc. 17 18 Below you can find some **don'ts** as well as what you should **do**. 19 20 ## `expected to find X artifacts for ids [id1 id2], found Y` 21 22 The `ids` property in the Dockers configuration tells GoReleaser which build IDs 23 to include. 24 You need to remove IDs that don't exist and/or don't build for the architecture 25 of the image being built. 26 Leaving it empty is also fine if you don't need any binaries. 27 28 ## `use docker --context=default buildx to switch to context "default"` 29 30 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". 31 32 You can switch to the default context using `docker context use default`. 33 34 This change should be persistent. 35 36 ### Don't 37 38 Build the binary again. 39 40 ```dockerfile 41 FROM golang AS builder 42 WORKDIR /app 43 COPY cmd ./cmd 44 COPY go.mod ./ 45 COPY *.go ./ 46 RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o app . 47 48 FROM scratch 49 COPY --from=builder /app/app /app 50 ENTRYPOINT ["/app"] 51 ``` 52 53 ### Don't 54 55 Copy from the `dist` directory. 56 57 ```dockerfile 58 FROM scratch 59 COPY /dist/app_linux_amd64/app /app 60 ENTRYPOINT ["/app"] 61 ``` 62 63 ### Do 64 65 Copy the clean file names from the root. 66 67 ```dockerfile 68 FROM scratch 69 COPY app /app 70 ENTRYPOINT ["/app"] 71 ``` 72 73 !!! tip 74 75 If you still want your users to be able to `docker build` without an extra 76 step, you can have a `Dockerfile` just for GoReleaser, for example, a 77 `goreleaser.dockerfile`.