The error UNABLE_TO_GET_ISSUER_CERT_LOCALLY indicates that Node.js (which npm runs on) cannot verify the SSL certificate presented by registry.npmjs.org. This typically happens in corporate environments where network proxies or firewalls intercept SSL traffic and re-sign it with their own certificate, which is not inherently trusted by the client.
You've done a good job adding the certificate to the system's CA store with update-ca-certificates and also trying npm config set cafile. However, for Node.js applications (like npm), the most reliable way to ensure custom CA certificates are trusted is by using the NODE_EXTRA_CA_CERTS environment variable. This tells Node.js where to look for additional trusted certificates.
Here's how to fix your Dockerfile:
Key Changes:
- Remove
npm config set cafile: While it can work, NODE_EXTRA_CA_CERTS is generally more robust for Node.js applications as it directly influences Node's SSL/TLS behavior.
- Set
NODE_EXTRA_CA_CERTS: Point this to the system's combined CA certificate bundle (/etc/ssl/certs/ca-certificates.crt), which is updated by update-ca-certificates.
Revised Dockerfile Snippet: