0

I am trying to start a MySQL docker instance, and want to interface to this server with PHPMyAdmin.

My server host name from where docker is running is <ServerName>

I am using the following command to start my MySQL docker container

docker run -P --name mysql-test -v storage-test:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=MyDataBase -e MYSQL_USER=me -e MYSQL_PASSWORD=mepass -d mysql:latest

And it seems to start and create the database correctly after that i start PHPmyAdmin container

docker run --name myadmin -d -e MYSQL_ROOT_PASSWORD=root -e PMA_HOST=ServerName -e PMA_VERBOSE=MyDataBase -e PMA_USER=me -e PMA_PASSWORD=mepass  -p 8080:80 phpmyadmin/phpmyadmin

I get this log from mySql container

MySQL init process done. Ready for start up.

2019-10-01T11:36:35.909758Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-10-01T11:36:35.909856Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.17) starting as process 1
2019-10-01T11:36:37.735204Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-10-01T11:36:37.761004Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2019-10-01T11:36:37.776949Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.17'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
2019-10-01T11:36:37.887863Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060

However when I access the PHPMyAdmin weblogin I get the following Error:

  • MySQL said: Documentation Cannot connect: invalid settings.
  • mysqli_real_connect(): (HY000/2002): Connection refused
  • phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.

If I remove the -e PMA_USER=me -e PMA_PASSWORD=mepass from the run command I get to the login where I can enter my credentials however when trying to do that I just get the

  • mysqli_real_connect(): (HY000/2002): Connection refused

Can anyone see what I'm doing wrong here ?

Here is a link to the two docker containers I am using

https://hub.docker.com/_/mysql

https://hub.docker.com/r/phpmyadmin/phpmyadmin/

Regards

Ephreal
  • 1,835
  • 2
  • 18
  • 35

1 Answers1

1

First of all, don't use -P when running your mysql container. -P (or --publish-all) will publish the ports of the MySQL container, which means MySQL will be accessible publicly. This is likely not what you want.

Containers can connect with each-other using the docker container-container network; if both containers are connected to the same network, they can connect with each-other over that network, without having to make the ports publicly accessible. Only use -p (or -P) to make ports accessible that should be public.

For example;

1. Create a custom network;

docker network create myprivatenetwork

2. Start the mysql container

Start the mysql container, and connect it to the myprivatenetwork. I removed the -P option, which means the container is not publicly accessible, but it is accessible from network(s) it's connected to. (I wrapped the commands to make it easier to read)

docker run \
  --name mysql-test \
  --network myprivatenetwork \
  -v storage-test:/var/lib/mysql \
  -e MYSQL_ROOT_PASSWORD=root \
  -e MYSQL_DATABASE=MyDataBase \
  -e MYSQL_USER=me \
  -e MYSQL_PASSWORD=mepass \
  -d \
  mysql:5.7

Note: I used mysql:5.7, because mysql:latest (which currently is MySQL 8) requires some additional configuration; see PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client In general, it's recommended to be specific about the version you want to run, and don't run :latest, as it may change to newer versions, which can cause your setup to fail.

3. Start the PhpMyAdmin container

Start the PhpMyAdmin container, and connect it to the same network; phpmyadmin can connect with the mysql container using its name (mysql-test) as hostname, and using the default mysql port (3306). For the phpmyadmin container, I kept -p to allow accessing it publicly (although you may want to have it run with TLS/SSL)

docker run \
  --name myadmin \
  --network myprivatenetwork \
  -d \
  -e MYSQL_ROOT_PASSWORD=root \
  -e PMA_HOST=mysql-test \
  -e PMA_PORT=3306 \
  -e PMA_VERBOSE=mysql-test \
  -e PMA_USER=me \
  -e PMA_PASSWORD=mepass  \
  -p 8080:80 \
  phpmyadmin/phpmyadmin

4. Visit http://localhost:8080 in your browser

You should now be able to visit PhpMyAdmin in your browser, and see the MySQL database.

Note that PhpMyAdmin is not configured with a password or TLS/SSL, so if your machine is publicly accessible (internet, or your local network), this will allow others to access your database through phpmyadmin

thaJeztah
  • 27,738
  • 9
  • 73
  • 92
  • Made it work had to add the following til mysql-test : "-h mysql-test" because it looked like phpadmin could not quit find it. and add to myadmin "PMA_verbose=MyDataBase". – Ephreal Oct 02 '19 at 06:55
  • Scratch the "PMA_verbose=MyDataBase" I misunderstood what it purpose was – Ephreal Oct 02 '19 at 07:43
  • The `-h mysql-test` should not be needed, as it's set automatically (if the container is named `mysql-test`) – thaJeztah Oct 02 '19 at 14:39
  • Well I thought so too however i got an error when I tried to connect to the database. and setting the host fixed this – Ephreal Oct 04 '19 at 08:14