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 172.0.0.1 inside my container which is the IP docker0 network.

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

  • Need to install Perl AND Linux
  • Jenkins docker plugin and linked slaves
  • R - install.packages not working in docker on coreos on compute engine
  • Best way to use mysql for docker based microservices
  • /opt/ansible/ansible/bin/ansible-playbook: no such file or directory ERROR: Encountered errors while bringing up the project
  • Can docker “instance” run totally in ram?
  • iptables -t nat -A PREROUTING ! -i docker0 -p tcp --dport 80 -j DNAT --to-destination 172.17.0.7:80
    

    where 172.17.0.7 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.

  • Pushing Docker Hub images to private Docker Registry
  • Upgrade of docker gitlab image to 8.6 breaks gitlab
  • Elastic Beanstalk Multicontainer Docker with private repository CannotPullContainerError
  • Jenkins - Docker integration
  • Running Unity3d for automated builds inside a docker container
  • Docker/Boot2Docker/Fig + RabbitMQ host issue; pika.exceptions.AMQPConnectionError: [Errno -2] Name or service not known
  • 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.

    --userland-proxy=false
    

    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.