Docker Community Forums

Share and learn in the Docker community.

Configure Docker to use a proxy server

Well all my ‘problems’ and questions are handled good! Thank you guys for any reply that helped me a lot. I got serveral Wordpress containers with all there own stuff, databases can only get access from localhost and I got NextCloud running in container with all configurations good and like I wanted, even with two-step verification as well…

Nou I want to use https://docs.docker.com/network/proxy/ to set domain names to IP:Poort and I would like you advise how this works.

PLEASE READ COMMENTS IN CODE BELOW

{
 "proxies":
 {
   "default": #what does they mean with default? I have serveral websites, what should I do?
   {
 "httpProxy": "http://127.0.0.1:3001", # let's say this is one website
 "httpsProxy": "http://127.0.0.1:3001", # I think this is the same, but secure
 "noProxy": "*.test.example.com,.example2.com" # are this the domain names that point to IP above?
   }
 }
}

And what do I have to do with this .json file if I have websites like this:
website one http://120.120.120.120:8080
website two http://120.120.120.120:8000
website three http://120.120.120.120:8088 etc etc

{
 "proxies":
 {
   "default":
   {
 "httpProxy": "http://120.120.120.120:8080", 
 "httpsProxy": "http://120.120.120.120:8080", 
 "noProxy": "domain1.com" 
   }
   {
 "httpProxy": "http://120.120.120.120:8000", 
 "httpsProxy": "http://120.120.120.120:8000", 
 "noProxy": "domain2.com" 
   }
   {
 "httpProxy": "http://120.120.120.120:8088", 
 "httpsProxy": "http://120.120.120.120:8088", 
 "noProxy": "domain3.com" 
   }
 }
}

Do I understand it correct?

(Think) what you describe is a reverse proxy, as in a single entrypoint that routes traffic to the target backends based on ip:port, domain name and port or url path.

Though, the link is about a forward proxy, which is typicaly found in enterprise environments, where direct internet access is prohibited and traffic to the internet needs to send thru a foward proxy (typical a http proxy) instead.

I am quite sure you will find many post regarding reverse proxies. You can either use something like Traefik (highly recommended!) or jwilder’s nginx-proxy where routing is configured using labels on target containers or use nginx/apache to manualy maintain your reverse proxy rules. Make sure the domain names you want to use are known by your dns server. Without working name resolution it is worth nothing if a reverse proxy is listening on a domain name, but the client is not able to resolve it…

1 Like

Traefik looks perfect to me! Thanks

Method 1 : Configuring proxy variables in the /etc/sysconfig/docker file

  1. Add following configuration in /etc/sysconfig/docker file:

cat /etc/sysconfig/docker

export HTTP_PROXY=“http://USERNAME:PASSWORD@[your.proxy.server]:[port]”
export HTTPS_PROXY=“https://USERNAME:PASSWORD@[your.proxy.server]:[port]”
For example :

cat /etc/sysconfig/docker

HTTP_PROXY=“http://user01:password@10.10.10.10:8080
HTTPS_PROXY=“https://user01:password@10.10.10.10:8080
2. Restart the Docker daemon after setting up the proxy.

service docker restart

Method 2 : Configuring environment variables

  1. Create a drop-in

mkdir /etc/systemd/system/docker.service.d

  1. Create a file with name /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:

[Service]
Environment=“HTTP_PROXY=http://user01:password@10.10.10.10:8080/”
Environment=“HTTPS_PROXY=https://user01:password@10.10.10.10:8080/”
Environment=“NO_PROXY= hostname.example.com,172.10.10.10”
3. reload the systemd daemon

systemctl daemon-reload

  1. restart docker

systemctl restart docker

  1. Verify that the configuration has been loaded:

systemctl show docker --property Environment

Environment=GOTRACEBACK=crash HTTP_PROXY=http://10.10.10.10:8080/ HTTPS_PROXY=http://10.10.10.10:8080/ NO_PROXY= hostname.example.com,172.10.10.10