PHPunit through docker : Could not translate host name to address

Hello there !

I'm trying to set up PhpStorm to run my Phpunit tests on my Docker container.

I have 3 containers : webapi (where my PHP code is) and db. Now first of all, my current architecture runs just fine in general and especially when I run tests in remote CLI, so i'm already certain my issue is how to configure PhpStorm.

I've set up a remote interpreter on my webapi container and mapped my folders. My unit tests work. But when I run my functional tests (which need to reach the DB), I get this :
Doctrine\DBAL\Exception\ConnectionException : An exception occurred in driver: SQLSTATE[08006] [7] could not translate host name "db" to address: Name or service not known

I went into my container settings. I've found a "Links" section. I've added my other container inside, then when I try to run my tests, I get this :

16:09 Error running 'tests': Cannot link to /db, as it does not belong to the default network. To fix it change project interpreter or check settings.

 

I assume it comes from how PhpStorm starts the container, but I can't figure how to set it up to recognize my db container.

 

Any idea ?

0
3 comments

Is it pure Docker without the Docker-compose usage? Did you consider switching to it?

How do you run those tests manually linking those 2 containers?

0

Hello,

 

I am using docker-compose. It is how I build and run them manually : My webapi has a "depends_on" setting over db.

0

"Links" section is available for pure Docker PHP Interpreters only. 

If you add your PHP interpreter as Docker Compose you won't be able to configure container settings & links.

Here's docker-compose:

vs just docker:

 

Please double check your configuration. 

If that doesn't help: to avoid any further confusion it would be great if you could attach screenshots of your exact config.

0

Please sign in to leave a comment.