Docker: npm install behind proxy

前端 未结 5 1729
粉色の甜心
粉色の甜心 2021-02-04 05:56

I have this Dockerfile:

FROM node:argon

ENV http_proxy http://user:pass@proxy.company.priv:3128
ENV https_proxy https://user:pass@proxy.company.priv:3128

RUN m         


        
5条回答
  •  粉色の甜心
    2021-02-04 06:06

    I also had the same issue and did not want to set any proxy information in my image as I did not want be dependant of my company environment.

    My solution was to use a cntlm running in gateway mode. To do so I put the flag Gateway set to yes the following allow rules in my cntlm configuration file:

     Gateway         yes
     # Allow local
     Allow           127.0.0.1
     # Allow docker subnetwork
     Allow           172.17.0.0/16
    

    Then I was able to run my docker file by getting the dokcer0 interface address (got with ifconfigcommand):

    docker build -t my-image --build-arg HTTP_PROXY=http://172.17.0.1:3128 --build-arg HTTPS_PROXY=http://172.17.0.1:3128 .
    

    Same with docker run:

    docker run --rm -e HTTP_PROXY=http://172.17.0.1:3128 --build-arg HTTPS_PROXY=http://172.17.0.1:3128 my-image
    

    However please note that since docker 17.07 you can simply configure the docker client proxy.

    Hence your ~/.docker/config.json will be like

    {
      "proxies": {
          "default":{
              "httpProxy": "http://172.17.0.1:3128/",
              "httpsProxy": "http://172.17.0.1:3128/",
              "noProxy": "127.0.0.1,172.17.0.0/16,*.some.compagny.domain"
          }
    }
    

提交回复
热议问题