Docker and UFW with real IP

I have a docker setup which disabled its default behaviour of tampering with iptables. So all works perfectly fine that I can allow or block specific port to outside world by specifying rule on ufw. Until I found the problem of not able to access the real IP of client accessing the website. All I see is inside my container which is the IP docker0 network.

I found a solution that asked me to add the below to my iptables

  • Running Xephyr inside a docker container
  • ERROR: for couchbase-db driver failed programming external connectivity
  • How to disable the oom killer in linux?
  • “Error: The `libsass` binding was not found…” in nodejs 4.2.4 lts but not 5.4.1 using docker
  • Docker container hosting
  • Trouble using AUFS driver in docker with Ubuntu
  • iptables -t nat -A PREROUTING ! -i docker0 -p tcp --dport 80 -j DNAT --to-destination

    where is the IP of proxy container. Now the problem is this IP tend to change if it happen to reboot and then my rule will no longer be valid.

    Is there any elegant way of solving this issue without going in the route of assigning static IP to containers if at all it is possible.

    Let me know if you need to see any more details of my setup. I am happy to post them.

  • How to connect to a dockerized PostgreSQL from (an undockerized) Python app
  • Get composer (php dependency manager) to run on a docker image build
  • docker0 interface missing on osx
  • Using host environment variables with Dockerfile
  • docker custom network connexion refused between
  • Codeception web driver (Selenium on Docker) tests not working as unable to see other containers (works on my dev machine though?!)
  • One Solution collect form web for “Docker and UFW with real IP”

    You can try running dockerd without the userland proxy, which is the process that masks the IP.


    There are various issues in doing that though.

    Otherwise routing “real” IP’s to containers is the cleanest solution.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.