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

  • Why will my Nginx docker container not start when the --restart switch is specified
  • Docker compose version 2.1+ on mac
  • How do I connect to a docker container running on a different host on a mac?
  • Publishing Docker to AWS from Visual Studio
  • No network on host machine when running a Docker container
  • How to detect a docker daemon port
  • 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.

  • Set the Perl environment correctly in dockerfile
  • Kubernetes Jenkins swap space issue
  • MongDB with Docker Authentication
  • How to maintain repositories into a single repository
  • Setting up Text editor like Vim,Spacemacs to work with docker containers without installing tools on the host machine
  • Post a Json file to elasticsearch running on Docker, Kitematic on Windows 10
  • 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.