我尝试在 go 网络中使用 **private corp**
构建 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"]
并得到 x509: certificate signed by unknown authority
错误
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/v4@v4.0.0-preview1: 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
我试图在
X509: Certificate Signed by Unknown Authority (Running a Go App Inside a Docker Container)
和
docker build: cannot get the github public repository, x509: certificate signed by unknown authority
和
,但结果是一样的。
❗️如果添加 -insecure
标志
...
RUN go env -w GOPROXY=direct GOFLAGS="-insecure"
COPY go.mod go.sum ./
...
到 Dockerfile
👉🏻 unrecognized import path
错误 **wrap**
以前的 x509
错误和 unreachable
包更改为 golang.org/x/crypto
go: golang.org/x/crypto@v0.0.0-20200622213623-75b288015ac9: unrecognized import path "golang.org/x/crypto": https fetch: Get "https://golang.org/x/crypto?go-get=1": x509: certificate signed by unknown authority
有什么问题❓
(我知道问题出在 git
获取依赖项时的证书和身份验证中,但我尝试使构建图像的过程更常见)
😭 应对自我证书(
.crt
)有帮助1️⃣ 将
.crt
添加到所需的dir
2️⃣ 'builder'-container 的
COPY
证书