When the container is running on a host that is behind a corporate proxy, setting the proxy variables in npm config does not force npm to use the proxy when running an npm install. EDIT I confirmed that the container is trying to bypass the proxy by inspecting my AWS VPC Flow Logs.
Dockerfile:
FROM keymetrics/pm2:latest
WORKDIR /usr/src/app
RUN export https_proxy=$http_proxy && \
npm config set proxy $http_proxy && \
npm config set https-proxy $http_proxy
COPY package.json .
RUN npm config list && npm install
COPY . .
CMD [ "pm2-docker", "start", "app.js" ]
Command:
docker built -t <tag> --build-arg http_proxy=$http_proxy
Result:
Step 1/7 : FROM keymetrics/pm2:latest
---> 51e4768f2252
Step 2/7 : WORKDIR /usr/src/app
---> Using cache
---> 89c5ceb1fb5b
Step 3/7 : RUN npm config set proxy $http_proxy && npm config set https-proxy $http_proxy
---> Running in c57684fe32d5
---> c639679ae203
Removing intermediate container c57684fe32d5
Step 4/7 : COPY package.json .
---> 766ae6d99f23
Removing intermediate container 0264b7efe319
Step 5/7 : RUN npm config list && npm install
---> Running in 96f5f3e23d88
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.5.1 node/v9.3.0 linux x64"
; userconfig /root/.npmrc
https-proxy = "10.202.1.215:3128"
proxy = "10.202.1.215:3128"
; node bin location = /usr/local/bin/node
; cwd = /usr/src/app
; HOME = /root
; "npm config ls -l" to show all defaults.
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npmjs.org/ip failed, reason: connect ETIMEDOUT 151.101.200.162:443
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-04-10T14_54_48_596Z-debug.log
When the container is running on a host that is behind a corporate proxy, setting the proxy variables in
npm config
does not force npm to use the proxy when running annpm install
. EDIT I confirmed that the container is trying to bypass the proxy by inspecting my AWS VPC Flow Logs.Dockerfile:
Command:
Result: