2016.3 EAP Docker linked services?

As PHPStorm can now run PHPUnit via Docker, I've decided to try and give it a go. I'm new to Docker, so this might be my lack of understanding.


I've got the remote interpreter setup, and it does run phpunit within my container. Since my project requires a mysql server, I've used a docker-composer file to launch a mysql container, and my php container links to it.

However, when running it via PHPStorm, it's unable to see the mysql server on the link address.


Is this PHPStorm not supporting it, or likely to be something I've done wrong?


How is your php container is linked to a mysql container? 

Could you please attach a screenshot of the settings you're trying to get working with mysql server?

Most likely we would need to try to reproduce the same.





My PHP script is trying to connect to 'myproject-mysql', and it gets a DNS error saying it can't lookup the host


Could you please reproduce this and send us/upload somewhere idea.log (Help > Show log in ...) + attach a screenshot of an output with a host lookup error?


Is there somewhere private I can upload the log file?


You can use ftp://ftp.intellij.net/.uploads/ (anonymous login, .uploads directory has no permissions to list/download files, only for upload, so that other users will not be able to download your snapshots).




JoshGigg.log, restarted the IDE 16:45:34 to get some separation.




Whilst getting a screenshot of the PHPUnit config, I found the docker container box, which had a section for links.

Sorry, my mistake for not configuring it correctly.


For other people.


PHPUnit config: 


Docker container config within:



Thanks for the update!


After adding linked container I receive this message:

Error running tests (1): com.github.dockerjava.api.exception.InternalServerErrorException: {"message":"Cannot link to /app_mysql_1, as it does not belong to the default network"}


Any ideas?


I am getting this problem too, regarding cannot link, does not belong on default network

In order to run my multi-container setup, I use docker compose, which specifies networks which containers are on, to segregate which services see which other services, meaning I can run multiple copies of nginx/phpfpm on different networks, with different source codes.

From what I can see, Using PHP Remote interpreter inside Docker, lets me configure how the container I created is run, but does not let me choose what networks I want to join my container to.  For example, I cannot specify --net mycustomnet which mysql is running on, therefore the mysql is isolated and inaccessible to the docker container being run.

I can set links, but when setting links, I also need to set the network, but the "Edit Docker Container Settings" dialog does not give me a way to specify the network.

Perhaps you should add a field at the bottom of here, in order that I can add whatever custom parameters that I need, just in case you don't support in the future an option which I need, but you have not yet created a dialog interface for.


There's a "Command" field where you can specify Containers network options, have you tried it?


This command field is in the deployment options of the run configurations for docker, right?

This isn't from what I can see useful when wanting to run a container with phpunit and run all the unit tests on them, I cannot see how to configure a remote php interpreter, target a docker container, then use a deployment to configure it, its all very loosely defined and hard to see how all of those things couple together.

I also tried to use the docker tab to run a container for me, it does not respect depends_on, or doesn't understand it, cause it only starts one container, not the entire stack of them which that container depends on, so this functionality is a bit broken to be honest.


Chris: Change the Network mode to be the name of the network created by docker-compose (docker network ls). That seems to work for me.


The whole Docker integration with PHPStorm doesn't seem to work well with docker-compose. You end up having to duplicate a fair bit of stuff in the Settings.


Ah, thats an interesting side effect.  To be honest I think this implementation is pretty broken, they don't appear to have properly thought stuff out and its just confusing more than helpful.

Yeah, I also had problem with docker compose too, since a lot of web apps have databases and since in docker, one container one process, means with nginx, phpfpm and mysql you need three containers to run unit tests, this is a bit of an oversight just giving me a single docker run like ability when what I think most people need, is to run a docker-compose setup of multiple containers.


This post helped me to realize that PhpStorm does not use existing, running container.

I had problem with "connection refused" and linked container. I've set  "Network mode" to name of network created by docker-compose and now it works.


That's true, I was expecting to connect to my running container with all it's connections. Anyone knows if it's possible?



@Piotr I'm somewhat interested in if you were using PHPStorm or PyCharm in the above image.  in PyCharm it works, but in PHPStorm I've put the same details but they don't have any effect.  My final solution included a lot more as referenced in my bug report


@Mstreeter I've been using PHPStorm. Two weeks ago I've updated to version 2017.3 with docker-compose support. It simply works.


Name of the network which should be typed in "Network mode" can be found by:

docker network ls

IMO it would be way easier if we could just tell php storm to use docker exec before running the command.

Then there would be no need to for all the additional configuration, as well as no need to expose docker on TCP.

I can use `docker exec -ti container bash` and then run php unit from there with no problems and all connections to other containers work.

That's all fine and I have a script that actually does this for me already however, I would like to be able to click play on a single test function and have it work instead of running all my tests every time.


Hey Eugene, this does not let me add docker exec in-front of a php interpreter. Been poking around all the settings and I havnt been able to do it.

Also that documentation seems to indicate that the internal execution of docker-composer has changed and thats it.

I still cant manually give it a command to connect to a container.

I still see no way that I can add `docker exec mycontainer` in front of any php interpreter.


Oh, my apologies - I misread what this topic was about.
exec support is only implemented for Docker Compose, not for singular containers.


lol dammit Eugene you got my hopes up. Yeah the issue is running unit tests in docker. It works but you cant connect to any other containers etc.

If there was some way to configure the unit testing itself to add `docker exec` to the start of the command then it would be great. Don't need php storm to build containers and handle everything docker where all the docker setup is already done outside. Just need the unit test to be able to run the same way you run it manually in the existing container without having to expose each container via TCP and do a truckload of configuration.

The thought just occurred to me that we could edit the /vendor/bin/phpunit file or replace it with a wrapper shell script but then you'd have the problem of loosing this file every-time you do a composer install/update or cloning the project on another machine.

I think this is the right direction of thinking tho and could be the easiest solution. Is there any way to find out / edit how php storm is running php unit?


So, just to get it out of the way - is there any particular reason you can't use Docker Compose?

Because Docker Compose is what usually people use in case when there's more than one container involved, and that's why exec support for Docker haven't been and I think will never be implemented.


I guess it lack of understanding and not wanting to spend a lot of time learning about the configs and how to set it up.

My containers are already running and communicating with each other so I don't understand why I now need to try to get phpstorm to take over the building of containers and jump through a bunch of hoops just to get it to run a php script.

Just seems to me that using docker from command line as I already know how to do means I dont have to invest a lot of time learning and debugging configuration issues when everything is already working.

PS - it is time consuming. I spent nearly a full work day watching videos and reading guides and still couldn't get it to work witch lead me to this thread in the first place.


I ended up getting it to work for me. What did the trick was Osemka59's command to view the networks. I then realized I had another network running and used that instead, then the other image linked properly and I was good to go.


Please sign in to leave a comment.