I have an Ubuntu VM that I’ve spun up on my Mac. In the VM I have MySQL and Docker installed and I’m trying to run a container from a WordPress image and connect to MySQL on the host vm. The WordPress image documentation says to use:
$ docker run --name some-wordpress -e WORDPRESS_DB_HOST=10.1.2.3:3306 -e WORDPRESS_DB_USER=... -e WORDPRESS_DB_PASSWORD=... -d wordpress
I’ve substituted in the IP address assigned to the host vm and the appropriate user, password and database name environment variables. The container comes up but then shuts down after a short while and the docker logs show:
vagrant@docker-blogs:/vagrant$ docker logs je-wordpress
WordPress not found in /var/www/html - copying now...
Complete! WordPress has been successfully copied to /var/www/html
Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10
MySQL Connection Error: (2002) Connection refused
Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10
MySQL Connection Error: (2002) Connection refused
These repeat several times then it terminates.
Should this be doable? If so, what do need I use as the IP address for the host vm and do I need to configure anything else?
I assume you have default setting on that mysql.
You are trying to connect to your mysql from DIFFERENT network. This is forbidden by default in mysql.
Look for the setting of mysql:
grep bind-address /etc/mysql/my.cnf
grep skip-networking /etc/mysql/my.cnf
Comment out both of them (
#bind-address
, …), or delete them.restart your mysql service
service mysql restart
Allow the user to connect from the remote network. Connect to mysql and execute:
GRANT ALL ON database.* TO user@'xxx.xxx.xxx.xxx' IDENTIFIED BY 'PASSWORD';
change the database, user, xxx.xxx.xxx.xxx for the IP you are connecting from, and PASSWORD.
For enabling the IDontGiveADamn mode, just execute
GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'monkey';