This solution worked 100% for me.
1.How to make docker use the proxy to get the base image?
Just add HTTPS or HTTP proxy into environment into your command line
export HTTP_PROXY="socks5://proxyhost:1080"
export HTTPS_PROXY="socks5://proxyhost:1080"
sudo docker build
sudo docker pull
2.How to make docker use the proxy for the RUN and ADD instruction?
While @JSamir provided an answer, it seemed complex. Here is the solution explained in simple words:
You need to add --build-arg https_proxy=socks5://yourproxy:1080 --build-arg http_proxy=socks5://yourproxy:1080.
Important Note: Do not use single or double quotes (' or ") around the proxy address, as they prevented the proxy declaration from working in my case.
sudo docker build --build-arg https_proxy=socks5://yourproxy:1080 --build-arg http_proxy=socks5://yourproxy:1080 -t mycontainer:latest .