linux:containers:docker-proxy
                Linux set proxy
https://stackoverflow.com/questions/54218632/how-to-use-local-proxy-settings-in-docker-compose Proxy for linux CLI docker I did a bit more research and seem to have used better key words because I found my solution now. I wanted to share the solution with everyone, in case someone else may ever need it. Create folder for configuring docker service through systemd mkdir /etc/systemd/system/docker.service.d Create service configuration file at /etc/systemd/system/docker.service.d/http-proxy.conf and put the following in the newly created file [Service] # NO_PROXY is optional and can be removed if not needed # Change proxy_url to your proxy IP or FQDN and proxy_port to your proxy port # For Proxy server which require username and password authentication, just add the proper username and password to the URL. (see example below) # Example without authentication Environment="HTTP_PROXY=http://proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8" # Example with authentication Environment="HTTP_PROXY=http://username:password@proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8" # Example for SOCKS5 Environment="HTTP_PROXY=socks5://proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8" Reload systemctl so that new settings are read sudo systemctl daemon-reload Verify that docker service Environment is properly set sudo systemctl show docker --property Environment Restart docker service so that it uses updated Environment settings sudo systemctl restart docker
Test if proxy needed
#Is proxy set in environment?
env | grep -i https_proxy  2>&1 > /dev/null
ENVRC=$?
SERVER=$(env|grep -i https_proxy | cut -f2- -d= )
if [ ${ENVRC} = 0 ]; then:
   PROXY=yes
   printf \"proxy env variable set.\n\" >> /tmp/logfile.txt
 else
 PROXY=no
 printf \"Proxy env variable unset.\n\"
      #Is a proxy needed?
      printf \"Starting wget \n \" >> /tmp/logfile.txt
      wget --tries=1 --timeout=5 --quiet --output-document=index.html https://www.google.com
      WGETRC=$? 
      if [ -f index.html ]; then
              rm index.html
      fi
      printf \"wget RC is ${WGETRC} \n\" >> /tmp/logfile.txt
      if [ ${WGETRC} != 0 ]; then
              PROXYREQUIRED=Yes
              export http_proxy=http://a-proxy:8080
              export https_proxy=http://a-proxy:8080
      else
              PROXYREQUIRED=No
      fi
      printf \"Proxy required ${PROXYREQUIRED} \n\" >> /tmp/logfile.txt
   fi
fi
linux/containers/docker-proxy.txt · Last modified:  by andrew
                
                