PhpStorm 2017.1 Help

Docker

PhpStorm integration with Docker allows you to run your applications in variously configured development environments deployed in Docker containers.

Prerequisites

Make sure that the following prerequisites are met:

  • Docker is installed, as described on the page Docker Docs. You can install Docker on the various platforms:
    • Windows
    • macOS
    • Linux (Ubuntu, other distributions-related instructions are available as well)
  • Before you start working with Docker, make sure that the Docker integration plugin is enabled. The plugin is bundled with PhpStorm and is activated by default. If the plugin is not activated, enable it on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.

Overview of Docker support

The Docker integration plugin adds the following to PhpStorm:

Working with Docker: Process overview

  1. Install Docker and start the Docker daemon (on Windows and macOS - along with the Docker VM in which it runs). For the instructions, see Get Started with Docker.
  2. Make sure the Docker integration plugin is enabled.
  3. Create a Docker configuration. You can do that:
    • Separately, in the Settings / Preferences dialog: Ctrl+Alt+S | Build, Execution, Deployment | Docker | /help/img/idea/2017.1/add.png | Docker.
    • When creating a Docker Deployment run configuration: Run | Edit Configurations | /help/img/idea/2017.1/add.png | Docker Deployment, etc.
  4. Use the Docker Tool Window to manage your Docker images, containers and deployed applications.
  5. Configure the PHP and Node.js interpreters running in a Docker container, see Configuring Remote PHP Interpreters and Configuring Node.js Interpreters.

Configuring PhpStorm to work with Docker

  1. In the Settings / Preferences dialog, open the Docker page under Build, Execution, Deployment, and click /help/img/idea/2017.1/add.png to create a Docker configuration:
    /help/img/idea/2017.1/docker_settings.png
  2. In the Docker page, provide the following information:
    • Name. Here it is MyDocker.
    • API URL. Here it is http://localhost:2375.
    • Certificates folder. Here it is /Users/<user name>/.docker/machine/machines/default
  3. Apply the changes and close the Settings / Preferences dialog.

After that, you can configure a remote interpreter using Docker:

Creating a Docker Deployment run/debug configuration

Having set up Docker, create the run/debug configuration. The Docker Deployment run/debug configuration can be used to download and build the Docker images, to create and start the Docker containers.

First, in the Deployment tab of the Docker Deployment run/debug configuration dialog, specify the following:

  • Name. Here it is Start Docker.
  • Server. Here Docker server is selected from the drop-down list.
  • Deployment. Here Dockerfile is selected.
  • Image Tag. Here it is mysite.
  • Container. Here it is Docker_XDebug.
/help/img/idea/2017.1/ps_docker_run_config.png

Next, in the Container tab, specify the necessary parameters.
At this point we are interested in exposing 80 port of the container to be available from our local machine, so we should configure a port binding for that:

Container port: 80, Protocol: tcp, Host IP: empty, Host port: 8080

/help/img/idea/2017.1/docker_run_config1.png

Apply changes and close the Docker Deployment run/debug configuration dialog.

Working with Docker in PhpStorm

As all the tools are installed, and the integration is configured, the recently created Start Docker Run/Debug Configuration can be launched:

/help/img/idea/2017.1/rm_docker_run_config2.png

The Docker tool window opens, updating you on the provisioning status and the current state of all your Docker containers.

/help/img/idea/2017.1/docker_app_servers_tw.png

As soon as the process is completed and our Docker_Xdebug container status turns green, one can check how it works in the browser. You should be able to open it by the URL similar to http://192.168.99.100:8080/ (192.168.99.100 is an IP address of the default Docker machine, we've looked into where to get this parameter before). If you can't see the index.php execution results in the browser (that contains phpinfo(); in our case), make sure that you have specified the correct IP address and port bindings on the previous steps. In our example, everything is running fine on the port we've expected the app to be:

/help/img/idea/2017.1/docker_php.png

Managing Docker containers and other Docker-related actions in PhpStorm

From the Application Servers tool window, it’s easy to inspect containers and view running processes. PhpStorm also enables you to search through the logs, start and stop containers, and perform basic container management like creating and deleting containers. Each deployment in Docker is assigned a unique container ID - these are initially temporary containers, although they can be committed and saved for further distribution. On the Docker Hub registry, there are many such images available for you to try.

/help/img/idea/2017.1/docker_app_servers_tw1.png

Images in Docker are read-only - once committed, any changes to a container’s state will become part of a new image. When you have a stable build on one instance of Docker (on your development machine, staging server, or a cloud), reproducing the exact same build is as simple as (1) committing the Docker container, (2) pushing it to a registry (public or private), then (3) pulling the same image to another instance of Docker, running - wherever.

/help/img/idea/2017.1/docker_app_servers_tw2.png

See Also

Last modified: 19 July 2017