David Y.
—In the process of dockerizing my Go application, I encounter the following error on the go build
step:
main.go:6:2: github.com/yuin/goldmark/v@v1.7.4: Get "https://proxy.golang.org/github.com/yuin/goldmark/@v/v1.7.4.zip": tls: failed to verify certificate: x509: certificate signed by unknown authority
However, if I visit https://proxy.golang.org/github.com/yuin/goldmark/@v/v1.7.4.zip in my browser, the module is downloaded without a TLS error.
Here’s my Dockerfile, which I’ve placed in my project’s root directory:
FROM golang:latest as builder RUN mkdir /app COPY . /app WORKDIR /app # This step fails: RUN CGO_ENABLED=0 go build -o myApp ./main RUN chmod +x /app/myApp CMD [ "/app/myApp" ]
The most likely cause of this error is a mismatch between the CA certificates installed on your host device and the CA certificates installed in the docker container.
These could either be generic CA certificates or ones specific to your network. Many corporate networks require custom CA certificates to be installed, which are used to proxy all or most TLS traffic on the network.
If the issue is caused by missing generic certificates, you can fix it by installing the ca-certificates
package before building your application:
FROM golang:latest as builder RUN mkdir /app COPY . /app WORKDIR /app # new step: RUN apt install ca-certificates RUN CGO_ENABLED=0 go build -o myApp ./main RUN chmod +x /app/myApp CMD [ "/app/myApp" ]
If you encounter the same error after this change, the issue is network-specific and you likely need to install a CA certificate specific to your corporate network.
Many corporate networks require custom CA certificates, which are used to proxy all or most TLS traffic on the network.
If you’re using Google Chrome, Brave, Edge, or another Chromium-based browser, download the certificate as follows:
If you’re using Firefox, download the certificate as follows:
Now that you have the certificate, you can copy it into your container by changing the Dockerfile as below:
FROM golang:latest as builder RUN mkdir /app COPY . /app WORKDIR /app # install generic certificates: RUN apt install ca-certificates # install corporate certificate: COPY downloaded-cert.pem /etc/ssl/certs/downloaded-cert.pem RUN CGO_ENABLED=0 go build -o myApp ./main RUN chmod +x /app/myApp CMD [ "/app/myApp" ]
It should now be possible to build the container without further TLS errors.
Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
SEE EPISODESConsidered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
Here’s a quick look at how Sentry handles your personal information (PII).
×We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.
Am I included?We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII:
If you have any questions or concerns about your privacy at Sentry, please email us at compliance@sentry.io.
If you are a California resident, see our Supplemental notice.