Symfony 4 produces SQLSTATE[HY000] [2002] Connection refused using Docker containers Symfony 4 produces SQLSTATE[HY000] [2002] Connection refused using Docker containers docker docker

Symfony 4 produces SQLSTATE[HY000] [2002] Connection refused using Docker containers


Thanks a lot for your comment, it saved me some further hours of research lol. I would just add for newbies in Docker like me, that if you want to get your container IP you can run the following command (so that you won't have to look for in the whole configuration dump you get by using only inspect):

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' YOURCONTAINERID

Thanks again!


This issue was caused by a full lack of understanding for me on how the containers communicate amongst each other.

The web container and the db container are essentially on their own 'vpn' network which means that the web container can communicate with db directly and would then use the internal port (3306) based on my configuration.

So removing the port (which I had as the external port) from my .env files' DATABASE_URL value was the answer.

DANG!