If the Docker host is placed inside a proxy server, it needs to add the proxy configuration to each Dockerfile such as ENV http_proxy
.
Following allows transparent access from the container to outside without any proxy configuration.
- Set up the transparent proxy
- Apply iptables rule for the transparent proxy
Note that it solves only http access but not https access.
Install squid
and edit /etc/squid/squid.conf
.
Create /etc/systemd/system/docker-proxy-dnat.service
and start it.
sudo systemctl start docker-proxy-dnat
sudo systemctl enable docker-proxy-dnat
Example: access to www.google.com
curl http://www.google.com/
|
| DNAT rule:
| Rewrites destination of the packet to 172.17.42.1:9090
|
172.17.42.1:9090
|
| Squid:
| Proxies the request to 127.0.0.1:9090
|
127.0.0.1:9090
|
| SSH port forward:
| Forwards the request to your local proxy
|
Your local proxy
|
|
www.google.com