"npm install" fails with ECONNREFUSED while building Docker image

I’m trying to build a Docker image that contains NPM and installs some tools, but when I issue the install command, as in:

RUN npm install -g sfdx-cli

The build hangs for a while, and then a lot of errors are thrown. And it is the same error:

npm ERR! fetch failed
npm WARN retry will retry, error on last attempt: Error: connect ECONNREFUSED

Every other resource I find on the web by searching this error results in an answer/article about using NPM behind a proxy, but that is not the case here. I’m not behind a proxy.

What can I do to make this error stop?

Running RUN echo "${http_proxy}" && echo "${HTTP_PROXY}" in my Dockerfile while building I get the following output:

Step 8/16 : RUN echo "${http_proxy}" && echo "${HTTP_PROXY}"
 ---> Running in 09bfc89592ae

Removing intermediate container 09bfc89592ae

Source: StackOverflow