1

Here is the command I used to create containers :

docker network create prestashop

docker run -ti --name db --network prestashop -e MYSQL_ROOT_PASSWORD=1234 -p 3307:3306 -d mysql:latest

docker run -ti --name prestashop --network prestashop -e DB_SERVER=db -p 8080:80 -d prestashop/prestashop

With that I can access to the Prestashop installation however when I need to configure the database I get this error :

Database Server is not found. Please verify the login, password and server fields (DbPDO)

I'm using thoses fields :

Database server address : (for this one I tried :)  db | 127.0.0.1:3037 | 127.0.0.1

Database name : prestashop

Database login : root

Database password : 1234

And I'm stuck to this step

EDIT :

Tried :

  • Insert another computer the same commands, everything works until I try to connect from the prestashop database configuration.

  • Removing the -ti options from the command line like @balexandre said.

Update

The issue come from the MySQL Version 8. I changed the mysql:latest to mysql:5.7 and everything is working but this is not the version I'm looking for. I still have no clue why MySQL 8 doesn't work

ben-ju
  • 84
  • 1
  • 13
  • can you access the database from a GUI? meaning you can connect to the database? - [this is how I actually run my docker services](https://gist.github.com/balexandre/d0e0ef79c7c2d453eb85d3e17fbe3d51), in case you want to have a look – balexandre Jan 27 '21 at 11:07
  • Yes i'm using : mysql --host=127.0.0.1 --port=3307 --user=root --password=1234 and evrything seems to work – ben-ju Jan 27 '21 at 11:10
  • never worked with, but maybe investigating if PrestaShop can connect to any other port that is not the default one? – balexandre Jan 27 '21 at 11:11
  • yes it says that the default port is 3306 but you can specify by typing – ben-ju Jan 27 '21 at 11:12

3 Answers3

3

If you follow the documentation in Docker Hub, it says:

The MySQL server can be reached:

  • from the host using port 3307 (example: $ mysql -uroot -padmin -h localhost --port 3307)
  • from a container in the network using the URL some-mysql.

the interesting part should be the

from a container in the network using the URL some-mysql.

that means, as you have changed the name of your MySQL image to db that you should use dband not 127.0.0.1 because you told Docker that those 2 containers can only communicate through the prestashop network with --network prestashop

in other words, all will be fine if you simply replace the "Database server address" value with db

like:

enter image description here

balexandre
  • 73,608
  • 45
  • 233
  • 342
  • Yes, I tried this solution as mentionned in the doc, does this worked for you ? Because I still get the error – ben-ju Jan 27 '21 at 11:29
  • you can see it works for me, it says "Connection to MySQL server succeeded"... the warning is that it will create a new database as the one mentioned in "Database name" does not exist yet.... – balexandre Jan 27 '21 at 11:47
  • @ben-ju the only thing different is, I didn't use the interaction param, so I didn't run the docker commands with `-ti`, just removed that to run normally as I didn't need to jump inside the CLI – balexandre Jan 27 '21 at 11:53
  • sorry, I was in lunch break thanks for your response. I tried to recreate with the command and by removing the -ti, still have the same issue. I must have done something wrong if yours is working by the command I wrote – ben-ju Jan 27 '21 at 12:45
  • I've executed step by step and worked... try to remove the images and start again. Stop both containers, remove containers and then remove the images... – balexandre Jan 27 '21 at 20:05
  • I completely uninstalled docker, images, containers, networks. I tried using mysql:latest and mysql:8.0 and for both I can't connect to the database. But when I try to connect to my database with the command line you wrote : `mysql -uroot -padmin -h localhost --port 3307` I connect to my apache server and not the docker container. This one works `docker exec -it db mysql -uroot -p` – ben-ju Jan 28 '21 at 08:19
  • 1
    Thanks a lot for your patience, I really appreciate that you took time for a junior. I found the solution. Prestashop is not familiar with the plugin `caching_sha2_password` so I had to change it to mysql_native_password on the `root@%` user – ben-ju Jan 28 '21 at 08:50
3

Thanks to @balexandre for the help.

First setup the network and his two containers with the following command :

docker network create prestashop

docker run --name db --network prestashop -e MYSQL_ROOT_PASSWORD=1234 -p 3307:3306 -d mysql:latest

docker run --name prestashop --network prestashop -e DB_SERVER=db -p 8080:80 -d prestashop/prestashop

Then if you're using a recent version of prestashop 1.7.* and a MySQL Version 8.*

You might need to change the plugin used for the connection.

Connect to your mysql container bash :

docker exec -it db mysql -uroot -p

When you're on the MySQL command line check your users :

SELECT user,plugin,host FROM mysql.user;

Output :

+------------------+-----------------------+-----------+
| user             | plugin                | host      |
+------------------+-----------------------+-----------+
| root             | caching_sha2_password |           |
| mysql.infoschema | caching_sha2_password | localhost |
| mysql.session    | caching_sha2_password | localhost |
| mysql.sys        | caching_sha2_password | localhost |
| root             | caching_sha2_password | localhost |
+------------------+-----------------------+-----------+

To be able to configure your database on your prestashop you need to change the plugin for your root user with empty host

ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'ENTER YOUR PASSWORD';
FLUSH PRIVILEGES;

Everything must work now.

Check @balexandre answer to know what to do on the prestashop setup.

ben-ju
  • 84
  • 1
  • 13
1

In addition to @balexandre's answer, you also want to check remote access rights to the mysql server. To do so, open the container from which you want to access the mysql container in cli mode then try to connect to mysql using 'mysql -u root -p' command. Chances are you will get an error 1130 which means that the mysql server doesn't allow a remote connection. This is how to fix it : https://stackoverflow.com/a/19101356 After flushing privileges, the connection goes through.

Paul
  • 11
  • 1