403 Forbidden when downloading Go dependencies

Here’s the error:

 => ERROR [4/6] RUN go mod download                  6.9s
 > [4/6] RUN go mod download:                             
#7 6.683 go: github.com/klauspost/compress@v1.15.15: reading https://proxy.golang.org/github.com/klauspost/compress/@v/v1.15.15.zip: 403 Forbidden
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c go mod download]: exit code: 1
make: *** [deploy] Error 1

My dockerfile:

FROM golang:1.18-alpine
LABEL version="1.0"
WORKDIR $GOPATH/src/github.com/febriliankr/PACKAGE_NAME
COPY . .
RUN go mod download
RUN go mod verify
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/rest main.go
ENTRYPOINT ["/go/bin/rest"]

I have also tried replacing go mod download with go mod tidy and still got the same error, please help, thanks!

I’m not sure why the Go module proxy is returning 403, but you can set the environment variable GOPROXY=direct to bypass it.