# docker exec -it my_container bash root@container:/# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 172.19.0.1 0.0.0.0 UG 0 0 0 eth0 172.19.0.0 * 255.255.0.0 U 0 0 0 eth0 # mysql -uroot -p -h172.19.0.1 Enter password: ERROR 2003 (HY000): Can't connect to MySQL server on '172.19.0.1' (111)The only solution I found was create an alias to local network interface:
# sudo ifconfig lo0 alias 10.254.254.254 # ifconfig lo0: flags=80492. The next step is grant access to the db for user on binded ipmtu 16384 options=1203 inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 inet 10.254.254.254 netmask 0xff000000 nd6 options=201 ...
# mysql -uroot -p ... mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '';3. Next we need bind mysql address to 0.0.0.0 (any ip), so open /etc/my.cnf and add or edit string:
bind-address=0.0.0.0restart server
4. You should be able to connect to you host db from within the container now:
# docker exec -it my_container bash # mysql -uroot -p -h10.254.254.254 ... mysql>yep!