如何解析TLS:无法验证证书:x509:在Windows中构建go dockerfile时,由未知权限签署的证书

bfnvny8b  于 2023-04-11  发布在  Docker
关注(0)|答案(1)|浏览(1443)

我有下面的dockerfile,当我尝试运行docker build时,我得到一个错误。
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" ]

误差

$ 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/v5@v5.0.8: 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/v5@v5.0.8: 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/cors@v1.2.1: 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

有趣的是,当我直接点击浏览器https://proxy.golang.org/github.com/go-chi/chi/v5/@v/v5.0.8.zip上的网址时,它下载的zip文件就很好。
我被困在这个问题上,因为几天,并尝试了几乎所有类似的职位。
go版本go1.19.5 windows/amd 64
操作系统- windows

bqf10yzr

bqf10yzr1#

我通过将机器的证书添加到docker容器来解决这个错误:

COPY ca-bundle.crt /etc/ssl/certs/ca-bundle.crt
COPY ca-bundle.trust.crt /etc/ssl/certs/ca-bundle.trust.crt

相关问题