Building a docker image for a node.js app fails behind proxy

柔情痞子 提交于 2019-12-01 00:50:22

The approach using --build-arg is the correct one: you only want to use the proxy settings when building the Docker image, and not having them inside the Dockerfile so it is not tied to an specific environment (you don't need the ENV entries on it).

Your issue is that you are trying to use as cntlm proxy inside the docker build localhost, which is not valid since at build time it will point to the docker container running the build, but it should actually point to the address of your host offering cntlm in the docker network.

In order to make that work, you can configure your cntlm to listen in several interfaces, and then activate gateway mode so you can use it from other machines. This way, when your image is being built, you will send the requests from the docker instance to the host.

My docker bridge network is as follows (my host gets as address in docker0

$ docker network inspect bridge
            "Config": [
                "Subnet": "",
                "Gateway": ""

In my cntlm.conf:

Gateway yes
Deny            0/0

With this config, cntlm will listen to both localhost and the docker bridge network, only allowing remote connections from any docker container.

You then use the proxy settings when building your image with npm:

$ docker build --build-arg=HTTP_PROXY= --build-arg=HTTPS_PROXY= .

I hope that helps, I know that making all of this in corporate networks is really a pita!

EDIT 18-aug-2016

Something I discovered today is, if you use docker-compose files with v2 format, starting the compose file will create a new network for your containers. This means that you need to adapt your cntlm file accordingly to accept connections from those new ranges.

As an example, one of my compose files has just created a network under, but my cntlm config only allowed connections from Check your syslog to identify the issue if you experience connection problems.