- Overview of Docker support
- Working with Docker: Process overview
- PhpStorm and Docker integration configuration
- Launching default Docker machine and getting necessary parameters
- Configuring PhpStorm to work with Docker
- Creating a Docker Deployment run/debug configuration
- Working with Docker in PhpStorm
- Running Docker from PhpStorm
- Managing Docker containers and other Docker-related actions in PhpStorm
- Debugging PHP web application running in the Docker container
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:
- Plugin Docker integration is installed.
The plugin is not bundled with PhpStorm, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
Overview of Docker support
The Docker integration plugin adds the following to PhpStorm:
- Docker configurations. These are named sets of settings for accessing the Docker Remote API.
- Docker Deployment run/debug configurations. They let you download and build Docker images, and create and start Docker containers. Application debugging is supported only for PHP.
- Docker tool window that lets you manage your Docker images and containers.
- Docker Registry configurations that represent your Docker image repository user accounts.
Working with Docker: Process overview
- Install Docker and start the Docker daemon (on Windows and OS X - along with the Docker VM in which it runs). For corresponding instructions, see Get Started with Docker.
- Create a Docker configuration. You can do that:
- Create a Docker Deployment run configuration.
- Execute the run configuration.
- Use the Docker Tool Window to manage your Docker images, containers and deployed applications.
PhpStorm and Docker integration configuration
At this point you have Docker and Docker Integration plugin for PhpStorm installed, so we can start with integration configuration.
Launching default Docker machine and getting necessary parameters
- Open the Docker Quickstart Terminal application. Docker will launch a default VM providing output in the console:
- In the Docker console, run the console command
docker-machine env default. Thus you will get all the necessary parameters - you'll need them later for PhpStorm configuration (such as
Configuring PhpStorm to work with Docker
- In the Settings / Preferences dialog, open the Docker page under Build, Execution, Deployment, and click to create a Docker configuration:
- In the Docker - Docker page, provide the following information:
- Name. Here it is Docker.
- API URL. Here it is https://192.168.99.100:2376. This value is taken from the console output (in the
second step of the previous procedure.)
Pay attention to the protocol change:
tcp(in the second step of the previous procedure) has changed to
- Certificates folder. Here it is
- Apply the changes and close the Settings / Preferences dialog.
Creating a Docker Deployment run/debug configuration
Having set up Docker, create the run/debug configuration.
- Name. Here it is Start Docker.
- Server. Here Docker server is selected from the drop-down list.
- Deployment method. Here Dockerfile is selected.
- Image tag. Here it is mysite.
- Container name. Here it is Docker_Xdebug.
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
Apply changes and close the Docker Deployment run/debug configuration dialog.
Working with Docker in PhpStorm
Running 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 opens, updating you on the provisioning status and the current state of all your Docker containers:
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
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
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:
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.
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 (http://192.168.99.100:8080/ in our case).
The major difficulty in getting Xdebug (or Zend Debugger) working with PhpStorm and
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:
#Set up debugger RUN echo "zend_extension=/usr/lib/php5/20131226/xdebug.so" >> /etc/php5/apache2/php.ini RUN echo "xdebug.remote_enable=1" >> /etc/php5/apache2/php.ini #Please provide your host (local machine IP) instead of 192.168.2.117 RUN echo "xdebug.remote_host=192.168.2.117" >> /etc/php5/apache2/php.ini
In the example above we're modifying
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 (where PhpStorm is running, in our case it is
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).