Docker container running golang http.Client getting error `certificate signed by unknown authority`

前端 未结 2 1639
孤街浪徒
孤街浪徒 2020-12-15 19:49

I created a docker container for talking to the google api using GoLang. I started off using a SCRATCH container and am getting the error certificate signed by unknown

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 20:50

    With scratch, you need to include the trusted certificates in addition to your application inside the image. E.g. if you have the ca-certificates.crt in your project to inject directly:

    FROM scratch
    ADD ca-certificates.crt /etc/ssl/certs/
    ADD main /
    CMD ["/main"]
    

    If you are using a multi stage build and only want the certificates packaged by the distribution vendor, that looks like:

    FROM golang:alpine as build
    # Redundant, current golang images already include ca-certificates
    RUN apk --no-cache add ca-certificates
    WORKDIR /go/src/app
    COPY . .
    RUN CGO_ENABLED=0 go-wrapper install -ldflags '-extldflags "-static"'
    
    FROM scratch
    # copy the ca-certificate.crt from the build stage
    COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
    COPY --from=build /go/bin/app /app
    ENTRYPOINT ["/app"]
    

提交回复
热议问题