I was having the hardest time getting applications in docker containers to connect to the instance of mysql runnning on the host.
I finally found a great solution, so I figured I'd post it here for myself and so that others may find it as well.
route_localnetfor docker0 interface:
sysctl -w net.ipv4.conf.docker0.route_localnet=1
iptables -t nat -I PREROUTING -i docker0 -d 172.17.0.1 -p tcp --dport 3306 -j DNAT --to 127.0.0.1:3306 iptables -t filter -I INPUT -i docker0 -d 127.0.0.1 -p tcp --dport 3306 -j ACCEPT
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
172.17.0.1- which is the host's IP from the view of the container.