Error connecting to Mysql with PHP and Docker

Asked

Viewed 212 times

0

I am running the Docker and in the settings step correctly the credentials for the connection to Mysql(Mariadb), but always returns the following error:

http://localhost/error.php?err=Unable%20to%20connect%20to%20MySQL

That is: 'Unable to connect to Mysql'.

In the Docker settings file are the credentials:

HOST=localhost USER=root PASSWORD=password DATABASE=db

The password is different from the one being informed above. I’m using Ubuntu and I’ve even created another user with the same root privileges, but always happens the same thing.

When I access Mysql by Dbeaver stating the credentials it can access normally and perform all operations, it is only when loading the Docker and try to open in the browser that these problems happen.

  • Please demonstrate the code used to connect to the server.

  • The PHP application is running in another container - or the same - or is running from host? Include your Compose - by the tag you are using Compose -, dockerfile, what is needed to reproduce the problem.

  • I managed to solve my problem by uploading an image of Mariadb along with PHP and HTTPD on Docker, I will add as an answer if someone also needs.

1 answer

1


I was able to solve the problem by climbing a Mariadb container along with the other containers I was already using and I used the Portainer tool to manage the containers and see which ip’s and ports to direct.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.