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?

0
28 comments

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.

0

https://gist.github.com/giggsey/bc7f271facf373cf0ffa82d9bbac3d66

 

 

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

0

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?

0

Is there somewhere private I can upload the log file?

0

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).

0

Thanks.

 

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

 

 

0

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:

 

2

Thanks for the update!

0
Avatar
Mindaugas Maciulaitis

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?

0

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.

1

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

0

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.

0

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.

0

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.

0

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.

1

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

 

0

@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

0

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

0

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

docker network ls
1

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.

1

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.

0

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

0

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?

0

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.

0

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.

0

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.

0

Please sign in to leave a comment.