Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 19 Next »


Docker is an open platform for building, shipping and running distributed applications. It gives programmers, development teams and operations engineers the common toolbox they need to take advantage of the distributed and networked nature of modern applications.

This tutorial describes Docker support in PhpStorm, which includes debugging PHP web applications running in the Docker container, inspecting, managing containers and viewing running processes.You can also search through logs, start and stop containers, and perform basic container management.


Docker installation

First of all, you'll need to install Docker and related tools so that you can take advantage of the Docker integration in PhpStorm. Please refer to the Docker documentation to get more information about the installation process:

Docker integration plugin installation

You will also need to install the Docker integration plugin in PhpStorm. Open Settings (Preferences) | Plugins, and click the Install JetBrains plugin... button:

Search for Docker and install the Docker Integration plugin by using the context menu.

Restart the IDE to complete the installation of the plugin.

PhpStorm & Docker Integration Configuration

At this point you have Docker and Docker plugin for PhpStorm installed, so we can start with integration configuration.

Launching default docker machine and getting necessary parameters (Windows / Mac OS X)

  1. Open the Docker Quickstart Terminal application (for Linux you need to use a standard terminal executing a sudo docker run hello-world command)
  2. Docker will launch a default VM providing output in the console:

  3. Run docker-machine env default console command to get all the necessary parameters, as we'll need them later for PhpStorm configuration (such as DOCKER_HOST and optional DOCKER_CERT_PATH):

    Please refer to the Docker Networking Documentation to learn more on how the IP address is assigned, and other networking configuration issues.


Launching default docker machine and getting necessary parameters (Linux)

  1. Use the standard Linux terminal to execute a sudo docker run hello-world command to start Docker
  2. You'll need two parameters of your Docker environment to configure PhpStorm at the next step:
    1. DOCKER_HOST which is a standard Host IP address which is always the same on Linux (, please refer to the Docker Networking Documentation to learn more
    2. (optional) DOCKER_CERT_PATH (see more info in the documentation)

Configuring PhpStorm to work with Docker

  1. Open Settings / Preferences | Build, Execution, Deployment | Clouds and create Docker configuration with a + button:

  2. You need to provide the configuration name (Docker in our case), API URL ( in our case, taken from the previous step's console output, please note the protocol change, tcp has been changed to https), Certificates folder (/Users/mikhailvink/.docker/machine/machines/default in our case):



    Please note that you will need to provide a socket path in the API URL field on Linux machines instead of the URL (usually it's unix:///var/run/docker.sock by default):

  3. Apply the configuration and close the Settings / Preferences dialog.
  4. Create a new Docker Deployment Run/Debug Configuration invoking the dialog from the Run | Edit configurations... menu:

    Then, create a Docker Deployment configuration with a + button:

  5. Provide all the necessary parameters on the Deployment tab. In our case we've provided Run/Debug Configuration Name (Start Docker in our case), selected the server (Docker), selected the Deployment method to be Dockerfile, Image tag (mysite), and Container name (Docker_Xdebug):


  6. Provide all the necessary parameters and configurations on the Container tab. 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):

    In addition, we can configure links, volume bindings, environment variables, and much more.

  7. Apply the Run/Debug Configuration and close the dialog.



At this step it's important to note that that there are many ways to create/configure Docker containers and VM images, and we'd recommend to always refer to the Docker documentation on the official web site.

For the purposes of this tutorial we're using Dockerfile and Apache configuration file, we've also created an index.php file with phpinfo(); to be deployed to the Docker container. We're making some significant configuration in those Dockerfile and Apache configuration file, so you're recommended to have a look at them. You can download entire project used in this demo or separate config files (apache-config.conf, Dockerfile) which then need to be placed in the project root folder.

Working with Docker in PhpStorm

Running the Docker from PhpStorm

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

The Application Servers tool window will be opened updating you on the provisioning status and current state of all your Docker containers: (view gif showing a full process)

As soon as the process is completed and our Docker_Xdebug container status turned green, we can check how it works in the browser. You should be able to open it by the URL similar to ( 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 (containing phpinfo(); in our case), please check 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:


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. You can also search through 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.

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.


Debugging PHP web application running in the Docker container

Assuming that you already run the Docker container now (and everything worked well on the previous steps), you should now able to open your PHP web application in the browser by http://host:port URL ( in our case). The major difficulty in getting Xdebug (or Zend Debugger) working with PhpStorm & Docker integration is the correct configuration of the Docker container.

In our case we're using a Dockerfile (we've already shown this config earlier and provided links to download it) to configure the container, including Xdebug-specific parameters, such as:

In the example above we're modifying /etc/php5/apache2/php.ini providing a path to Xdebug extension, and some other Xdebug parameters (remote_enable and remote_host). Please note that xdebug.remote_host value should be replaced with your local machine IP address which is visible from the Docker container (where PhpStorm is running, in our case).

Configuration for Zend Debugger is similar, please see a full tutorial on installing Xdebug and installing Zend Debugger (there's more information on required parameters and options).

Don't forget to re-run Start Docker Run/Debug Configuration so that all the changes are applied.

As soon as all the configs are in place, the debugging process can be triggered following this tutorial from step 2 (start Listening for PHP Debug Connections, set a breakpoint in the source code, start a debug session in the browser, reload the current page, debug).


  • No labels