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.
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.
In the URL address bar, click the security icon that appears before the URL.
Click “Connection is secure”
Click “Certificate is valid”
Click Details tab
In Certificate Hierarchy section, select the root parent.
In Certificate Fields section, select the root parent.
Click Export…
In the file that is downloaded, open it in Notepad.
Copy everything.
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.