Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

curl refuses HTTPS inside a Docker container because of the certificate

Errorcurl exits with code 60: the remote server's SSL certificate was deemed not OK

Short answer

curl checks the server certificate against a CA store, and a slim image may have none. Check with curl -v what the store is, then fix the matching cause: install the ca-certificates package, add your own CA file and run update-ca-certificates, or correct a CURL_CA_BUNDLE path. Do not use -k as a fix.

  • Applies to curl 8, Debian 12 base image, Docker Engine 27
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run curl verbosely inside the container. It shows which CA file or folder it uses and where the check stops.

    docker exec -it app curl -v https://example.com
    docker exec app env | grep -E 'CURL_CA_BUNDLE|SSL_CERT'
  2. 2Match what you see, then jump to its fix

    1. 1Every HTTPS site fails, and the verbose output shows no usable CA fileThe image has no CA store installedFix
    2. 2Public sites work, but an internal host, a self-signed server or a TLS-inspecting proxy failsOnly your own server or company proxy fails: its CA is not trustedFix
    3. 3curl exits with code 77, or fails even though ca-certificates is installedCURL_CA_BUNDLE points at a file that is missing or unreadableFix

What does the error look like?

  • curl exits with code 60: the remote server's SSL certificate was deemed not OK
  • curl exits with code 77: problem reading the CA certificate file
  • the same URL works on the host but fails inside the container

Cause 1 of 3

The image has no CA store installed

1Check

curl's own guide lists 'no CA store installed' as a reason verification fails. On Debian the store comes from the ca-certificates package, which holds the Mozilla CA list.

docker exec app dpkg -s ca-certificates
docker exec app ls /etc/ssl/certs/ca-certificates.crt

2Fix

Install the package in the Dockerfile, in the same layer as the other apt step.

RUN apt-get update \
 && apt-get install -y --no-install-recommends ca-certificates \
 && rm -rf /var/lib/apt/lists/*

3Verify

Rebuild and call a public HTTPS URL.

docker build -t app .
docker run --rm app curl https://example.com

Confirmed by curl.se

Did this fix it?

Cause 2 of 3

Only your own server or company proxy fails: its CA is not trusted

1Check

The certificate is signed by a CA that is not in the container's store. curl's guide names a self-signed certificate and a CA missing from the store as reasons for failure.

docker exec app curl -v https://internal.example.com 2>&1 | grep -i -E 'issuer|verif'

2Fix

Add the CA certificate (PEM, .crt extension) to the image and rebuild the store. For one-off transfers, --cacert with that file does the same job for a single request.

COPY my-root-ca.crt /usr/local/share/ca-certificates/my-root-ca.crt
RUN update-ca-certificates

3Verify

The internal URL now answers without any extra flag.

docker run --rm app curl https://internal.example.com

Confirmed by manpages.debian.org

Did this fix it?

Cause 3 of 3

CURL_CA_BUNDLE points at a file that is missing or unreadable

1Check

curl reads CURL_CA_BUNDLE when it is set and uses it in place of its default. Code 77 means the CA file could not be read: check the path and access rights.

docker exec app printenv CURL_CA_BUNDLE
docker exec app ls -l "$(docker exec app printenv CURL_CA_BUNDLE)"

2Fix

Point the variable at a real PEM file that the container user can read, or remove the variable so curl uses its default store.

# Dockerfile
ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

3Verify

Repeat the failing request.

docker run --rm app curl https://example.com

Confirmed by curl.se

Did this fix it?

How do I stop it coming back?

  • Install ca-certificates in every slim or minimal base image that makes HTTPS calls.
  • Keep company CA files in the repo and add them in the Dockerfile, never with -k in scripts.
  • Set CURL_CA_BUNDLE only when you must, and test the path in the build.
  • Run one HTTPS request as a build or CI smoke test.

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.