apt-get in docker behind corporate proxy

后端 未结 4 1266
深忆病人
深忆病人 2021-02-14 18:17

I\'m attempting to set up a development environment behind a corporate proxy server with Docker. Try as I might, I cannot get the docker container to talk to the proxy server.

4条回答
  •  不知归路
    2021-02-14 18:52

    If you are building behind the firewall, you MUST use Docker 1.9.x build-args.

    Building a Dockerfile without the build args fails and blocks as follows:

    3b0d8aa7c417: Pull complete
    Digest: sha256:dc31e6056d314218689f028b51a58b2ca69b1dfdc5f33ead52b9351e9a19ee85
    Status: Downloaded newer image for nodesource/trusty:4.2.3
     ---> e17bee681d8f
    Step 2 : RUN apt-get update
     ---> Running in bdaf0006ccbd
    

    Apt-get blocks here because it does not have connectivity with archive.ubuntu.com... You can verify that by running the image...

    # docker run -ti --net=host --rm nodesource/trusty:4.2.3 bash
    root@pppdc9prd9rj:/usr/src/app# apt-get update
    0% [Connecting to archive.ubuntu.com (91.189.92.201)]^C
    root@pppdc9prd9rj:/usr/src/app# ping archive.ubuntu.com
    PING archive.ubuntu.com (91.189.91.24) 56(84) bytes of data.
    ^C
    --- archive.ubuntu.com ping statistics ---
    3 packets transmitted, 0 received, 100% packet loss, time 1999ms
    

    Using the build-arg solves the problem....

    # docker build -t migrator --build-arg http_proxy=$HTTP_PROXY .
    
    arg http_proxy=$HTTP_PROXY .
    Sending build context to Docker daemon 3.333 MB
    Step 1 : FROM nodesource/trusty:4.2.3
     ---> e17bee681d8f
    Step 2 : RUN apt-get update
     ---> Running in 019b32d09a77
    Ign http://archive.ubuntu.com trusty InRelease
    Get:1 http://archive.ubuntu.com trusty-updates InRelease [65.9 kB]
    Get:2 http://archive.ubuntu.com trusty-security InRelease [65.9 kB]
    Get:3 http://archive.ubuntu.com trusty Release.gpg [933 B]
    Get:4 http://archive.ubuntu.com trusty Release [58.5 kB]
    Get:5 http://archive.ubuntu.com trusty-updates/main Sources [326 kB]
    Get:6 http://archive.ubuntu.com trusty-updates/restricted Sources [5217 B]
    Get:7 http://archive.ubuntu.com trusty-updates/universe Sources [1
    

提交回复
热议问题