Skip to content

Instantly share code, notes, and snippets.

@ahbanavi
Last active December 9, 2024 20:27
Show Gist options
  • Save ahbanavi/dbc944dcf88700e48a8533a64b3e5343 to your computer and use it in GitHub Desktop.
Save ahbanavi/dbc944dcf88700e48a8533a64b3e5343 to your computer and use it in GitHub Desktop.
Dcoker Bind NIC (Network Interface)
# Interface to bind in this example
# ID: wlan0, IP: 192.168.10.183, Gateway: 192.168.10.1
docker network create -d bridge --subnet=172.18.0.0/16 --gateway=172.18.0.1 -o com.docker.network.bridge.enable_ip_masquerade=false -o com.docker.network.bridge.name=docker_binded docker_binded
echo '1 docker_binded' >> /etc/iproute2/rt_tables
ip rule add from 172.18.0.0/16 tab docker_binded
ip route add 172.18.0.0/16 dev wlan0 tab docker_binded
ip route add default via 192.168.10.1 dev wlan0 tab docker_binded
iptables -t nat -A POSTROUTING -s 172.18.0.0/16 ! -o docker_binded -j SNAT --to-source 192.168.10.183
ip rule add to 172.18.0.0/16 lookup main priority 10
# and then attach the network to container
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment