Docker: PhpMyAdmin communicating with MySQL container with IPtables / UFW
Important:
localhost on PhpMyAdmin is really the localhost of the container, not of the server hosting docker
Two methods:
A) Via docker NAT (internal to the NAT):
a1) Find the IP of mysql container:
docker inspect mysql
e.g. "IPAddress": "172.17.0.3"
a2) Copy config.inc.php to the host filesystem to edit it
docker cp phpmyadmin:/etc/phpmyadmin/config.inc.php .
a3) Add the IP found on step a1 and add it
Refer to How to Add Multiple Hosts in phpMyAdmin
<https://tecadmin.net/add-multiple-hosts-in-phpmyadmin/#>
e.g.:
$i++;
$cfg['Servers'][$i]['host'] = '172.17.0.3'; //provide hostname and port if other than default
$cfg['Servers'][$i]['user'] = 'root'; //user name for your remote server
$cfg['Servers'][$i]['password'] = 'myrootpass'; //password
$cfg['Servers'][$i]['auth_type'] = 'config'; // keep it as config
a4) Copy it back to the container
docker cp config.inc.php phpmyadmin:/etc/phpmyadmin/
a5) Restart the container
docker restart phpmyadmin
B) Routing through the host (default, easier)
[haven't tested but this should work -- only needed if you have security tighten]
If 172.17.0.1 the IP of docker's NAT gateway (get it also via docker inspect mysql)
sudo iptables -I DOCKER 7 -p tcp -s 172.17.0.1 -d 172.17.0.3 --dport 3306 -j ACCEPT
(if there's already 7 rules in the docker part of iptables -- check it via sudo iptables -S)
Sem comentários:
Enviar um comentário