Thursday, January 28, 2021

Docker Behind Proxy on CentOS - Solution to Many Issues

If you running docker behind proxy on CentOS and receiving timeout or network errors, then use below steps to configure proxy settings on your CentOS box where docker is installed and you are trying to build docker image:

Login as the user which is going to build image


Create directory with sudo

    Sudo mkdir -p /etc/systemd/system/docker.service.d


Create file for http proxy setting

    /etc/systemd/system/docker.service.d/http-proxy.conf

    and insert following content into it:

    [Service]

    Environment="HTTP_PROXY=http://yourproxy.com:80/"


Create file for https proxy setting

    /etc/systemd/system/docker.service.d/https-proxy.conf

    and insert following content into it:

    [Service]

    Environment="HTTPS_PROXY=https://yourproxy.com:80/"


Restart the systemctl daemon

systemctl daemon-reload


Restart the docker:

service docker restart


Also if you are trying to install Yarn or NPM within your dockerfile , then within your docker file define following environment variables

ENV http_proxy=http://yourproxy.com

ENV https_proxy=http://yourproxy.com

ENV HTTP_PROXY=http://yourproxy.com

ENV HTTPS_PROXY=http://yourproxy.com


Notice that only specify http protocol both for https and http proxy. 

I hope that helps.

Restart docker again.


No comments: