I am having below dockerfile and when I try to run docker build, I get an error.
dockerfile
# base go image
FROM golang:latest as builder
RUN mkdir /app
COPY . /app
WORKDIR /app
RUN CGO_ENABLED=0 go build -o brokerApp ./cmd/api
RUN chmod +x /app/brokerApp
# build a tiny docker image
FROM alpine:latest
RUN mkdir /app
COPY --from=builder /app/brokerApp /app
CMD [ "/app/brokerApp" ]
error
$ docker build -t test -f broker-service.dockerfile .
Sending build context to Docker daemon 7.79MB
Step 1/10 : FROM golang:latest as builder
---> c48137eaf961
Step 2/10 : RUN mkdir /app
---> Running in 0caaa78d39ad
Removing intermediate container 0caaa78d39ad
---> 260a46b545a8
Step 3/10 : COPY . /app
---> 17c49c16a2ea
Step 4/10 : WORKDIR /app
---> Running in 056c8e90776a
Removing intermediate container 056c8e90776a
---> 55ef7bc5f453
Step 5/10 : RUN CGO_ENABLED=0 go build -o brokerApp ./cmd/api
---> Running in e1d6ae8ddbb6
go: downloading github.com/go-chi/chi/v5 v5.0.8
go: downloading github.com/go-chi/cors v1.2.1
cmd/api/routes.go:6:2: github.com/go-chi/chi/[email protected]: Get "https://proxy.golang.org/github.com/go-chi/chi/v5/@v/v5.0.8.zip": tls: failed to verify certificate: x509: certificate signed by unknown authority
cmd/api/routes.go:7:2: github.com/go-chi/chi/[email protected]: Get "https://proxy.golang.org/github.com/go-chi/chi/v5/@v/v5.0.8.zip": tls: failed to verify certificate: x509: certificate signed by unknown authority
cmd/api/routes.go:8:2: github.com/go-chi/[email protected]: Get "https://proxy.golang.org/github.com/go-chi/cors/@v/v1.2.1.zip": tls: failed to verify certificate: x509: certificate signed by unknown authority
The command '/bin/sh -c CGO_ENABLED=0 go build -o brokerApp ./cmd/api' returned a non-zero code: 1
Interestingly, when I directly hit the url on browser https://proxy.golang.org/github.com/go-chi/chi/v5/@v/v5.0.8.zip
, it downloads the zip just fine.
I am stuck on this issue since a couple of days and have tried almost all similar posts.
go version go1.19.5 windows/amd64
os- windows
2
Answers
I solved this error by adding the machine’s certificates to docker container:
I just had the same error. In my case I was using
ubuntu
as the base image for my container which happen didn’t provide the root certificates needed by my application to trust the targeted service. I switched tocentos
as my base image and it worked fine.