Connect container without NAT

Answering my own question if anyone in the future wants to do the same.

I initially tried by changing the config of the Docker bridge driver. For example, shutting off masquerading, and setting the bridge name on the host machine. That didn’t seem to work for me. Maybe there is a way to get this to work, but if you do, you’re relying on under the hood Docker stuff to manage this.

The better way is to manually create a bridge on the host, manually create veth pairs, and hook everything up manually, then update the routing table in the container to use the veth pair instead of the eth0 interface that gets connected to the docker0 bridge (or user-defined bridge).

Here’s a nice blog which shows how to do this:
http://blog.oddbit.com/2014/08/11/four-ways-to-connect-a-docker/

The second example called “With Linux Bridge devices” is the one that allows you to bypass NAT.

Sidenote, of course, another option for bypassing NAT is to use Swarm. But just an FYI, that uses VXLAN which introduces a lot of overhead on the network stack.