go build or go mod download inside Docker fails with an unknown authority error
tls: failed to verify certificate: x509: certificate signed by unknown authorityShort answer
Go inside the container found a certificate whose issuer is not in the trust store it reads. That is typical behind a company proxy that re-signs HTTPS traffic. Put the proxy's root certificate into the image and point Go at it with SSL_CERT_FILE. For image pulls, trust is the Docker daemon's, not Go's.
Fix it fast
1Find out which cause you have
Find out which program fails: the Go command inside the build step, or the Docker daemon pulling the base image. The line before the error tells you.
docker build --progress=plain -t my-go-app . 2>&1 | grep -n -B3 "x509"2Match what you see, then jump to its fix
What does the error look like?
tls: failed to verify certificate: x509: certificate signed by unknown authoritythe error appears in a RUN go mod download or go build step of a Dockerfile
Cause 1 of 2
Go inside the build container does not trust the proxy's root certificate
1Check
UnknownAuthorityError means the issuer of the certificate is unknown. Inside the build, the system store comes from the image, not from your Windows or Mac host.
docker run --rm golang:1.24 sh -c 'echo $SSL_CERT_FILE; ls /etc/ssl/certs | head -n 3'2Fix
Copy your organisation's root certificate (PEM) into the image and set SSL_CERT_FILE or SSL_CERT_DIR so Go reads it. Go honours both variables as overrides for its default locations.
FROM golang:1.24
COPY corp-root-ca.pem /usr/local/share/corp-root-ca.pem
ENV SSL_CERT_FILE=/usr/local/share/corp-root-ca.pem
RUN go mod download3Verify
Rebuild; the download step passes.
docker build --progress=plain -t my-go-app .Confirmed by pkg.go.dev
Cause 2 of 2
The failing request is the Docker daemon's own pull, not Go's
1Check
The daemon trusts a registry's CA by a certificate placed in a directory named after that registry. On Linux these roots are merged with the host's system defaults; Docker Desktop can also use the host certificate store.
ls /etc/docker/certs.d/2Fix
On a Linux engine, add the registry's CA file as a .crt in /etc/docker/certs.d/<registry-host>/ . On Docker Desktop, install the root certificate into the host's trusted store.
sudo mkdir -p /etc/docker/certs.d/registry.example.com
sudo cp ca.crt /etc/docker/certs.d/registry.example.com/ca.crt3Verify
Pull the image again.
docker pull registry.example.com/team/base:latestConfirmed by docs.docker.com
How do I stop it coming back?
- Keep the corporate root certificate in the repository and copy it in a build stage, not in each project by hand.
- Never disable verification to make a build pass; trust the right root instead.
- Run the same Dockerfile on a machine outside the proxy in CI, to catch environment-only trust problems.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
curl refuses HTTPS inside a Docker container because of the certificate
curl exits with code 77: problem reading the CA certificate file
curl checks the server certificate against a CA store, and a slim image may have none.
3 causes, each with a fixServers
docker pull or push fails against a private registry without valid HTTPS
Error response from daemon: v1 ping attempt failed with error
Docker treats every registry as secure except local ones.
3 causes, each with a fixServers
docker pull fails with net/http: TLS handshake timeout from the registry
net/http: TLS handshake timeout
The Docker daemon, not your shell, opens the connection to the registry, and its TLS handshake did not finish in time.
2 causes, each with a fixServers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fix