<p>A container running behind a K8s service fails to make network requests with the error <code>x509: certificate signed by unknown authority</code>.</p>
<p>The container is an API that serves incoming requests and makes external network requests before responding, it's running in a local K8s cluster managed by Docker desktop. The third party API being called is failing the certificate validation and Im not using a proxy or VPN.</p>
<p>What could be the cause of this?</p>

<p>I hope this helps someone else as there are many different discussions about this topic online.</p>
<p>The fix seems to be that when doing a multi stage docker build and using e.g. <code>FROM golang:alpine3.14 AS build</code> along with  <code>FROM scratch</code>, the root certificates are not copied into the image.</p>
<p>adding this to the Dockerfile after the <code>FROM scratch</code> line removes the error.</p>
<pre><code>COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
</code></pre>
<p>This was found on this <a href="https://stackoverflow.com/a/52979541/356387">stackoverflow answer</a></p>
