Connection refused Laravel & MariaDB

Hello,

I am deploying an application with the following technologies: (Laravel+MariaDB+phpMyAdmin)

In the dockerfile the application image is created and in the docker-compose all the services are orchestrated within a network and through environment variables defined in the .env they are called ports and passwords.

Unfortunately there is something that does not work correctly because you do not have access to the DB, to inspect each container the logs were used but they do not show any errors and when trying to connect remotely to the DB if I have a connection, pinging from one container to another there is also a connection , even within the application container to the database.

env

When using a shared compose file, you can access your DB from any of those containers within the same the Docker network using database:3306 (service name and default port).

The ports is not relevant when inside a Docker network, it maps the ports to the outside world. Usually only your app or your reverse proxy (in front of your app) uses ports.

change your DB_HOST to db (your service db name ) check docker-compose ps