New Docker-Compose Support in PhpStorm 2017.2

Gary Hockin

PhpStorm has had Docker support for a while now, and using a Docker remote interpreter has been a relatively straightforward task for the last few releases. PhpStorm 2017.2 introduces native support for Docker Compose to make using Docker and PhpStorm even easier.

While Docker can handle single containers very nicely inside PhpStorm, often you should be defining multiple containers to handle different parts of your application; a container for your database, one for your web server, another for PHP, one for your memory cache, one for your queue and so on. This is considered the best practice when using Docker – one container per server, and in even rudimentary systems, these containers can ofter become numerous, with each container depending on one (or more) of the others.

Docker Compose is a tool for defining (and running) multiple container application in exactly the way defined above. You can define multiple containers in a `docker-compose.yml` file which (typically) lives in the root of your project, and then you can bring up your entire infrastructure using `docker-compose up`. This makes managing the web of containers needed to develop and (ultimately deliver your project using Docker Stack) much easier than having several individual docker files that need to be brought up in the right order.

If you’re not using Docker Compose and would like to learn more, I highly recommend this blog post by Matthew Setter.

PhpStorm 2017.2 makes it easier to use your PHP containers defined with Docker Compose as your remote interpreter of choice.  When you’re adding your interpreter, still select From Docker, Vagrant, VM, Remote… and you’ll notice the new Docker Compose option.

docker-compose-php

The Server option allows you to pick which Docker server to connect to (Docker for Mac, Docker Machine or direct TCP connection).  You then can tell PhpStorm which `docker-compose.yml` file to use as the Configuration file(s) and PhpStorm will then provide you with a list of containers to pick from in the Service drop-down. The Environment variables… setting allows you to set substitution variables for the `docker-compose.yml` file.

You can select any container that provides command-line PHP, and have multiple interpreters configured per-project – so if you want to have different containers for running PHP Unit configurations, one for running on PHP 5.6 and one for running on 7.1 for example, you can do that without a problem. You can still run your Behat, Codeception and PhpSpec tests using a Docker Compose interpreter, and you can find out more information about configuring those test frameworks in these videos.

Once you’ve configured your Docker Compose interpreter you’ll see that PhpStorm will infer the path mappings automatically from the `volumes` section of your configuration file.

docker-compose-mappings

Docker is an important area in both development and deployment so we’re always aiming to help make the integration with our IDEs as seamless as possible – we’re interested to hear what you have to say on the matter.

Note: Please note that Docker-compose configuration version 3 is not supported yet. We are working on it, please vote and follow the progress in the issue PY-22674.

– Gary & The PhpStorm Team

650x170_newsletter_PS_2017_2_@2x

 

Subscribe

Subscribe for updates