Reputation: 17606
I'm attempting to run a container with PhpMyAdmin that connects to the MySQL Community Server I installed on my Mac OS.
As can be seen below, MySQL is running.
As can be seen below, I can connect via terminal.
Using the following command:
mysql --host=localhost --port=3306 --user=root --password="o_oGLZDI<1-t"
I am unable to connect to MySQL properly with PhpMyAdmin from docker. I've tried the following command lines:
docker run --name myadmin -d -e PMA_HOST=127.0.0.1 -e PMA_PORT=3306 -p 8080:80 phpmyadmin/phpmyadmin
docker run --name myadmin -d -e PMA_HOST=localhost -e PMA_PORT=3306 -p 8080:80 phpmyadmin/phpmyadmin
They generate these errors, when I attempt login:
#2002 - Connection refused — The server is not responding (or the local server's socket is not correctly configured).
#2002 - No such file or directory — The server is not responding (or the local server's socket is not correctly configured).
What is the correct command line required to run docker with the correct configurations to connect to my MySQL Server Mac OS ?
Upvotes: 1
Views: 1475
Reputation: 30723
Your command:
docker run --name myadmin -d -e PMA_HOST=127.0.0.1 -e PMA_PORT=3306 -p 8080:80 phpmyadmin/phpmyadmin
This will point to localhost
but to the localhost
inside the phpmyadmin container and not to the localhost of your machine (where mysql is running).
You can run your container on your host network which will disable container networking. This means you will be able to reach your mysql container using localhost:
docker run --name myadmin --network=host -d -e PMA_HOST=127.0.0.1 -e PMA_PORT=3306 phpmyadmin/phpmyadmin
You can access your phpmyadmin on port 80 (not 8080) because the container network is not used when you specify --network=host
. (It could be you need to adapt your firewall to allow docker0)
Another option (a better one), especially for MacOS (since Docker version 17.06) is to use docker.for.mac.localhost
as PMA_HOST
. This should resolve to your mac internal address (but I was not able to test it for now).
docker run --name myadmin -d -e PMA_HOST=docker.for.mac.localhost -e PMA_PORT=3306 -p 8080:80 phpmyadmin/phpmyadmin
Upvotes: 5