This issue might occur if there is a http_proxy available on the HOST machine. Even if you set the proxy before running the "docker build" command, the error will be still present.
The issue occurs due to the below reason:
++++++++++++++Each step in a Dockerfile is executed in a new container. When running RUN export foo=bar, that variable is only present during that step, but no longer there in the next step (container)
++++++++++++++
Solution-1:
For docker build, you can use --build-arg, which sets environment variables in the container during build only, so they do not remain in the image after build. And there's no need to change your Dockerfile for http_proxy variables, as they are supported by default
For example
docker build --build-arg http_proxy=<ip>:<port> --build-arg http_proxy=<ip>:<port> -t image_name .
Note: If there is also a ftl_proxy then you can add another --build-arg for that.
useful link: https://github.com/moby/moby/issues/20394
Solution-2
Another solution to this issue is to add these proxy lines in the HOST machine's /etc/environment file and then reboot the machine.
Useful link: http://linuxexperimentation.blogspot.com/2011/12/setting-up-proxy-in-kubuntu.html