Home > Backend Development > Golang > How to Fix 'certificate signed by unknown authority' Errors in GoLang Docker Containers?

How to Fix 'certificate signed by unknown authority' Errors in GoLang Docker Containers?

DDD
Release: 2024-12-07 04:21:11
Original
523 people have browsed it

How to Fix

Resolving "certificate signed by unknown authority" Error in Docker Container for GoLang HTTP Client

When running a Docker container for accessing the Google API using GoLang's http.Client, you may encounter the error "certificate signed by unknown authority." This issue arises when the container lacks the necessary trusted certificates to verify the API server's certificate.

Scratch Container

With a SCRATCH container, it's crucial to include the trusted certificates in the container alongside your application. To achieve this, add the ca-certificates.crt file directly to the container:

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

Multi-Stage Build

If using a multi-stage build, you can leverage certificates packaged by the distribution vendor by modifying the Dockerfile:

FROM golang:alpine as build
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 --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /go/bin/app /app
ENTRYPOINT ["/app"]
Copy after login

By incorporating these modifications, you provide the container with the necessary certificates to establish a secure connection and eliminate the "certificate signed by unknown authority" error, enabling successful GoLang HTTP client interactions with the Google API.

The above is the detailed content of How to Fix 'certificate signed by unknown authority' Errors in GoLang Docker Containers?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template