PhpStorm integration with Docker allows you to run your applications in variously configured development environments deployed in Docker containers.
- Overview of Docker support
- Working with Docker: Process overview
- Configuring PhpStorm to work with Docker
- Creating a Docker Deployment run/debug configuration
- Working with Docker in PhpStorm
- Managing Docker containers and other Docker-related actions in PhpStorm
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:
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:
- Docker configurations. These are named sets of settings for accessing the Docker Engine API and Docker Compose.
You can create a Docker configuration in two ways:
- Create Docker Deployment run/debug configurations. They let you download and build Docker images, and create and start Docker containers.
To create a Docker Deployment run/debug configuration, do the following: . See the run configuration settings.
- Docker tool window () that lets you manage your Docker images and containers.
- Docker Registry configurations that represent your Docker image repository user accounts.
- Additional Docker option in the Configure PHP Remote Interpreter Dialog and in the Configure Node.js Remote Interpreter Dialog for configuring integration with remote PHP and Node.js interpreters running in a Docker container.
Working with Docker: Process overview
- 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.
- Make sure the Docker integration plugin is enabled.
- Create a Docker configuration. You can do that:
- Use the Docker Tool Window to manage your Docker images, containers and deployed applications.
- 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
- In the Settings / Preferences dialog, open the Docker page under Build, Execution, Deployment, and click to create a Docker configuration:
- In the Docker page, provide the following information:
- 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.
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
As all the tools are installed, and the integration is configured, the recently created Start Docker Run/Debug Configuration can be launched:
The Docker 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
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:
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.