Npm install in Docker tutorial is taking FOREVER

I ran into the same issue today.

The strict-ssl trick didn’t help, but I found the cause.

In my case (at least), the problem was not enough resources. I stopped a few containers to free up memory, and everything started working fine after that.

Hopefully, this saves someone some time.

1 Like

For anyone trying to run npm commands behind company firewall, and the npm commands fail when building a docker image, the docker line is not recommended:

RUN npm config set strict-ssl false

Instead, create a cacert.pem file in the same directory as the Dockerfile.

Retrieve a new certificate from your browser:

  1. Open https://google.com in a browser.
  2. In the URL address bar, click the security icon that appears before the URL.
  3. Click “Connection is secure”
  4. Click “Certificate is valid”
  5. Click Details tab
  6. In Certificate Hierarchy section, select the root parent.
  7. In Certificate Fields section, select the root parent.
  8. Click Export…
  9. In the file that is downloaded, open it in Notepad.
  10. Copy everything.
  11. Append it to the end of the cacert.pem file.

Then add the following commands to your Dockerfile prior to the npm commands:

COPY cacert.pem /usr/local/share/ca-certificates/cacert.pem
RUN npm config set cafile /usr/local/share/ca-certificates/cacert.pem

What we’re telling docker to do is to COPY the cacert.pem file (containing the certificate) into the image being created. Then we config npm to use the certificate in the cacert.pem file when making network requests. This allows npm to successfully go through the company firewall in a secure manner.

1 Like