How to configure PHPStorm to work with native Docker for mac

In the past few days I have tried to configure PHPStorm with Docker for mac, and I’ll list how you can do that cause sadly the documentation depend on the old docker version

1-You need to install the plugin

 

1

2

 

 

 

 

 

 

 

 

 

 

2- Next you will have to restart PHPStorm, mean while you will need to install a program called socat using homebrew using the following command

brew install socat

3- You will have to execute the following command every time you need want to use docker with PHPStorm

socat -d -d -lf /tmp/socat.txt TCP-L:2376,fork UNIX:/var/run/docker.sock

You can read more about socat from this link.

4- Now you will have to configure PHPStorm like the following

 

3 4 5

 

 

 

 

 

 

 

  • You will need to add the server, configure the URL, by default it will use the old URL for Docker toolbox, and since it cant read the Unix socket which Docker for mac use, we use socat to redirect the URL to the socket.
  • You will need to add the full path for docker-compose command , not sure why but PHPStorm didn’t find it.
  • The certification field should be removed, as this was related to the old Docker toolbox and no need for it any more.

5- To configure the debugger you should check do the following

 

6 7 8

 

 

 

 

 

 

 

 

 

 

 

for me, my project depend on a docker-compose.yml file, so I choose that one.

6- Make sure that you can start / stop Docker, so from the bottom toolbox you will find the Docker icon, clicking on it will open it and clicking on the Run button should show the images/containers that you have like

 

9 10

 

 

 

 

 

 

 

7- Run the debugger (running docker-compose) can be done like the following

 

11

 

 

 

 

 

 

And it will run docker-compose and create the image for you, and from there you can find many valuable information about your container

 

12

 

 

 

 

Hopefully this will change later, and it will be much simpler if (and only if) PHPStorm team found a better way to implement it.

 

Filed under: Other

15 Comments

  1. Thank you very much for this, I have notice that if you have a .env file and docker-compose.yml is outputting environments, it does not work as it should

    The .env file contains
    APP_ENV=local

    The docker-compose.yml contains
    `
    environment:
    APP_ENV: “${APP_ENV}”
    `

    PHPstrom does not import the value of local

    • In general `.env` files has nothing todo with the environment vars you add to your `docker-compose.yml`.
      Cause based on the definition when you set a value in the environment it will set it on the image as a system environment value like when you add it to your bashrc, meanwhile the `.env` file is only related to Laravel ( if am not mistaken you are talking about the environment file in laravel, other wise you need to clarify more).

  2. Also every time I deploy, my database is getting whipped. Seems the containers get deleted, and rebuilt so I’m loosing my dev data.

    • you will need to define a volume to your database container which can be used as the persistent place, if you like share your `docker-composer.yml` file as gist ( http://gist.github.com ) and I’ll be happy to help.

      or you can check this file and see how to define your database image and the volume so that it will not delete your database every time you run your containers.

  3. Have you managed to talk to php executable inside a docker container from phpstorm? We are trying to get phpunit test running it’s own dedicated container from inside PHPStorm.

    Anyway thank you for this post, I hope the plugin is getting updated to support native on mac. In the meantime, your post is making my life a little bit easier without needing to constantly lookup and save commands.

    • If you look closely at the link you put at the bottom you will notice that he mentioned my article as a reference ..

      so basically he is the one who copied my post and used my images not otherwise.

  4. Couldn’t go through this because phpstorm seems to run npm install. Had to revert to remote debugging with

    • not sure I follow up with you here, running npm install will be related to the Dockerfile that you have.
      This article talked about the general situation and was not specific to nodejs or PHP, if you share your Dockefile I might be able to help, though am not that expert with Docker


Add a Comment

Your email address will not be published. Required fields are marked *

Comment *

Name *
Email *
Website

4 × 5 =