I try to build go images in private corp network use docker-multi-stage-build:
FROM golang:latest as builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN GO111MODULE="on" CGO_ENABLED=0 GOOS=linux go build -o main ${MAIN_PATH}
FROM alpine:latest
LABEL maintainer="Kozmo"
RUN apk add --no-cache bash
WORKDIR /app
COPY --from=builder /app/main .
EXPOSE 8080
CMD ["./main"]
and get x509: certificate signed by unknown authority
error
Step 1/13 : FROM golang:latest as builder
---> 2421885b04da
Step 2/13 : WORKDIR /app
---> Using cache
---> 6555644dbd16
Step 3/13 : COPY go.mod go.sum ./
---> 55d45a30f492
Step 4/13 : RUN go mod download
---> Running in 88c21c6b4fab
go: github.com/dgrijalva/jwt-go/[email protected]: Get "https://proxy.golang.org/github.com/dgrijalva/jwt-go/v4/@v/v4.0.0-preview1.mod": x509: certificate signed by unknown authority
The command '/bin/sh -c go mod download' returned a non-zero code: 1
make: *** [docker] Error 1
I tried to find an answer in
X509: Certificate Signed by Unknown Authority (Running a Go App Inside a Docker Container)
and
docker build: cannot get the github public repository, x509: certificate signed by unknown authority
and
, but result is the same.
❗️If add -insecure
flag
...
RUN go env -w GOPROXY=direct GOFLAGS="-insecure"
COPY go.mod go.sum ./
...
to Dockerfile
unrecognized import path
error wrap previous x509
error and an unreachable package change to golang.org/x/crypto
go: golang.org/x/[email protected]: unrecognized import path "golang.org/x/crypto": https fetch: Get "https://golang.org/x/crypto?go-get=1": x509: certificate signed by unknown authority
What is the problem❓
(I understand that problem is in the certificates and authentication when git
get dependencies, but I try to make process of building images more common)
git
usescurl
to access thehttps
servers so you need to import the certificate into theCA store
of the system.The workaround is to define the environment variable
GIT_SSL_NO_VERIFY=1
on your Agent environment variables, but it doesn't work when usinggo get
orgo mod download
.To import the certificate on your system CA store the procedure depends on your OS you have to use
openssl
.For example
docker image build
output