7

Context: OS: Windows 10 Pro; Docker ver: 18.09.0 (build 4d60db4); Behind corporate proxy, using CNTLM to solve this issue. (currently pulling / running image works fine)

Problem: I was trying to build the following Dockerfile:

    FROM alpine:3.5
    RUN apk add --update \
        python3
    RUN pip3 install bottle
    EXPOSE 8000
    COPY main.py /main.py
    CMD python3 /main.py

This is what I got:

Sending build context to Docker daemon  11.26kB
Step 1/6 : FROM alpine:3.5
 ---> dc496f71dbb5
Step 2/6 : RUN apk add --update     python3
 ---> Running in 7f5099b20192
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.5/main: could not connect to server (check repositories file)
WARNING: Ignoring APKINDEX.c51f8f92.tar.gz: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.5/community: could not connect to server (check repositories file)
WARNING: Ignoring APKINDEX.d09172fd.tar.gz: No such file or directory
ERROR: unsatisfiable constraints:
  python3 (missing):
    required by: world[python3]
The command '/bin/sh -c apk add --update     python3' returned a non-zero code: 1

I was able to access the URL from a browser, so there is no problem with the server itself.

I suspected that it has something to do with the proxy not being propagated to the container, as explained in this question, since I also did not get the http_proxy line when running docker run alpine env. However, after entering the proxies into the config file, it finally appeared. Yet the problem still exists.

I also tried to change the DNS as instructed here, but the problem is still unsolved.

ehsan shirzadi
  • 4,709
  • 16
  • 69
  • 112
Leonard AB
  • 1,479
  • 1
  • 19
  • 30
  • [This](https://stackoverflow.com/questions/55079577/docker-connectivity-issue-apt-apk-do-not-work-inside-docker-container-and-durin?answertab=active#tab-top) was helpful for me. – Zeinab Abbasimazar Feb 18 '20 at 14:28

2 Answers2

9

I finally managed to solve this problem, and the culprit was my setting in the CNTLM. For a background story, please check this post.

The root cause of this problem is that the docker container could not access the internet from inside the VM due to wrong IP setting inside the CNTLM.ini.

Normally CNTLM listens to 127.0.0.1:3128 by default to forward the proxy. I followed the default, and thus set the proxy setting on Docker (for the daemon - through the GUI, and for the container - through config.json) is also set into that address and port. It turns out that this "localhost" does not apply to the VM where docker sits, since the VM has its own localhost. Long story short, the solution is to change that address into dockerNAT IP address (10.0.75.1:3128) in all of the following locations:

  • CNTLM.ini (on the Listen line. Actually if we use CNTLM for other purposes as well, it is possible to supply more than one Listen line)
  • Docker daemon's proxy (through the Docker setting GUI)
  • Docker container config.json (usually in C:\Users\<username>\.docker), by adding the following lines:

    "proxies":
     {
       "default":
       {
         "httpProxy": "http://10.0.75.1:3128",
         "httpsProxy": "http://10.0.75.1:3128",
         "noProxy": <your no_proxy>
       }
     }
    

also check these related posts:

Leonard AB
  • 1,479
  • 1
  • 19
  • 30
  • Listening on different ip didn't make it in my case. I made it work using host `host.docker.internal` for proxies in config.json – Simon30 May 03 '21 at 22:27
  • @Leonard AB. Thanks a lot. I use Windows 10 and Docker Desktop (Engine Version 20.10.6). I use px rather than CNTLM. It worked when I used "docker build --build-arg HTTP_PROXY=http://10.137.72.217:3128 --build-arg HTTPS_PROXY=http://10.137.72.217:3128 .", where 10.137.72.217 is the IPv4 address returned by running command "ipconfig". It failed with any other address, such as "localhost" or "127.0.0.1" (the latter is the value of "listen" in my configuration file px.ini). – Ivan dal Bosco Aug 05 '21 at 10:08
  • My issue is here is, I set proxy settings and they ended up not relevant. But those settings remained in `C:\Users\\.docker\config.json`. I needed to set the proxy settings off to my pull to work. "proxies": { "default": { "httpProxy": "", "httpsProxy": "" } } – Julien Nyambal Dec 13 '22 at 08:07
1

You can try to build your docker file with the following command:

docker build --build-arg http_proxy=http://your.proxy:8080 --build-arg http_proxy=http://your.proxy:8080 -t yourimage .
Mario Khoury
  • 372
  • 1
  • 7