I'm trying to connect a PHPMyAdmin-Container to a MySQL-Container to view the databases.
I have started the MySQL container via $ docker run --name databaseContainer -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql
and the PHPMyAdmin-Container via $ docker run --name myadmin -d --link databaseContainer:mysql -p 8080:8080 phpmyadmin/phpmyadmin
When trying to login on PHPMyAdmin, I get: mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: Name does not resolve
and
mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name does not resolve
By the way, I have also started a wordpress container and also linked it to mysql, there it works...
I've had the same error installing docker using laradock, then running docker-compose up. Out of the box, default config throws this error when you attempt to log into phpMyAdmin (using current images as of Oct 2018). The error was not present using docker run.
For docker-compose.yml (version 3), one cause is services running on different networks by default. For anyone else having this issue, here is a config that works for mysql and phpmyadmin.
Inside "docker-compose.yml" file, under "services":
Edit the ".env" file as follows:
Add the following line to the "/etc/hosts" file:
Assuming you're also using nginx, and that config is elsewhere in your "docker-compose.yml", you can build and start these services with:
Then navigate to localhost:8080 in your browser and login with username "root" and password "mypass" (leave server field blank).
Try executing the above command it will work, as phpmyadmin may have hardcoded the in their implementation that the mysql server conatiner name to be db.
If you still want to give your db server a unique name, add
PMA_HOST
environment variable:mysqlserver
is the name give to your mysql db server.In my case, I was using MySQL 8.0 and it turned out that mysql has introduced a new password identification which is not supported by phpmyadmin. See this answer.
Instead of starting them one by one, use
docker-compose
.Create a docker-compose.yml file
Then start it using
docker-compose up
in the same folder yourdocker-compose.yml
file is located. Access PHPmyadmin using the browser and use 'db' as the hostname of your database, since that is the name of the service in thedocker-compose.yml
file and therefore can be resolved using dockers internal DNS service to the actual ip of the docker-container. All the links are setup for you automatically.That's much simpler - docker run overcomplicates things and is not practical for those things - never.
Hint: if docker-compose is not installed on your machine, install it using this official docs https://docs.docker.com/compose/install/ (out of scope)
The configuration file of phpmyadmin/phpmyadmin (/www/config.inc.php) say by default the host name of database server if 'db' :
So if your database name container is not 'db', you should add the environment variable PMA_HOST= (or PMA_HOSTS if multi db servers) with the right name (databaseContainer in your case)
GIVEN you started the MySQL container as:
THEN you should actually create phpmyadmin as follows:
It is actually advisable that you include a network. So you would have:
AND
Make sure your network is created first: