[Docker]: Connecting PHPMyAdmin to MySQL doesnt work
Instead of starting them one by one, use docker-compose
.
Create a docker-compose.yml file
version: '2'
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: my-secret-pw
ports:
# just if you also want to access it directly from you host
# node neede for phpmyadmin
- "3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
depends_on:
- db
ports:
- "8080:8080"
Then start it using docker-compose up
in the same folder your docker-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 the docker-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' :
$hosts = array('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)