External docker container IP

Moki Lv6

Assumptions:

  • first IP: 11.11.11.11 (ens0)
  • second IP: 22.22.22.22 (ens0:0)

Verify network interfaces:

1
2
3
curl --interface ens0 https://httpbin.org/ip

curl --interface ens0:0 https://httpbin.org/ip

Create network and routing:

1
2
3
docker network create --attachable --opt 'com.docker.network.bridge.name=bridge-coi1' --opt 'com.docker.network.bridge.enable_ip_masquerade=false' bridge-coi1

iptables -t nat -A POSTROUTING -s $(docker network inspect bridge-coi1 -f '{{range .IPAM.Config}}{{.Subnet}}{{end}}') ! -o bridge-coi1 -j SNAT --to-source 22.22.22.22

Debug connection:

1
2
3
docker run --rm byrnedo/alpine-curl -s https://httpbin.org/ip

docker run --rm --network bridge-coi1 byrnedo/alpine-curl -s https://httpbin.org/ip

Example:

1
2
3
docker run --rm -p 11.11.11.11:1080:1080 -e PROXY_USER=proxy_login -e PROXY_PASSWORD=proxy_pass serjs/go-socks5-proxy

docker run --rm --network bridge-coi1 -p 22.22.22.22:1080:1080 -e PROXY_USER=proxy_login -e PROXY_PASSWORD=proxy_pass serjs/go-socks5-proxy

Use:

1
2
3
curl -s -x socks5://proxy_login:proxy_pass@11.11.11.11:1080 https://httpbin.org/ip

curl -s -x socks5://proxy_login:proxy_pass@22.22.22.22:1080 https://httpbin.org/ip
On this page
External docker container IP