Ярлыки

.htaccess (4) тестирование (8) шаблоны проектирования (3) css (5) Debian (6) docker (2) Doctrine2 (6) Git (6) html (4) java (6) javascript (13) jquery (11) LFS (3) linux (23) mac os (4) mod_rewrite (2) MSSQL (4) MySQL (18) ORM Doctrine (17) patterns (3) PDO (3) perl (7) PHP (64) PHPUnit (8) Python (15) SEO (2) Silex (1) SimpleXML (1) SQL (14) ssh (4) Ubuntu (24) Yii1 (1) Zend Framework (19) ZendFramework2 (8)

среда, 12 октября 2016 г.

Docker. OSX connect to the host from container (xdebug, mysql).

1. I use Docker for Mac 1.12.1 and wasn't able connect to the host from within container by gateway ip:
# 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=8049 mtu 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
...
2. The next step is grant access to the db for user on binded ip
# 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.0
restart 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!