T1k3
T1k3

Reputation: 101

PhpStorm Docker PHPUnit Database

Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve (SQL: select * from tablename)

The test working in container but broken in IDE. Do you have any ideas what is the problem in PhpStorm?

Upvotes: 10

Views: 5355

Answers (4)

cvegabon
cvegabon

Reputation: 17

I have solved the same issue as @jason-adams said here, but you have to be careful with the network name, just in case you want to use the network name you have used in your docker-compose file.

In this file I have something like:

networks:
  backend_blablabla:

...but when I ran docker network ls I saw a slightly different network name, in my case, it was something like {PROJECT_NAME}_backend_blablabla

So I had to use it on Settings > PHP > Test Frameworks > (clicked the folder) on my Docker container > Network mode because the network name of the docker-compose file won't work.

Upvotes: 0

Jason Adams
Jason Adams

Reputation: 213

I ran into this exact issue. Assuming you already have the Docker container and PHP interpreter set up, this is how I got it to connect to the MySQL container:

  1. Run docker network ls from the CLI and saw the "lighthouse_default" network
  2. Went to PHP > Test Frameworks and edited (clicked the folder) on my Docker container
  3. Set Network mode to "lighthouse_default"
  4. Added the lighthouse_mysql_1 image to the Links section

Obviously, in your situation the network name will likely be different. The real point is that I had to make sure I was using the right network and make sure the database image is in the Container Links.

Upvotes: 14

xayer
xayer

Reputation: 479

I have a same problem and found solution:

Go to:

Settings > Languages & Frameworks > PHP > Test Frameworks

Open:

Edit docker container settings (you need push on folder icon)

Inside opened window, you will find "links" section, add from list your database container and after saving all works perfect!


If you get error for different network configuration, update your docker-compose.yml with adding this sentence on each container:

network_mode: bridge

Upvotes: 2

J_Heimbach
J_Heimbach

Reputation: 61

Do you use docker-compose (and is your db running in a different container)?

Check if your CLI Interpreter is running with docker-compose settings

Upvotes: 6

Related Questions