Integrating PhpStorm with Docker on Mac

PhpStorm has a good Docker integration that offers ability to run and debug PHP from inside Docker containers and controlling Docker containers and images from PhpStorm UI.

However, PhpStorm doesn’t currently support communicating with Docker via Unix socket. Up to version 2017.1.3 for Mac, it still requires a TCP port.

There’s a solution for that: use socat.

Socat would open a TCP port connected to the UNIX socket. Brilliant, isn’t it?

The command you need to run is:

socat TCP-LISTEN:2375,reuseaddr,fork,bind=localhost UNIX-CONNECT:/var/run/docker.sock

I’m not sure about you but I hate running commands manually every restart. I want to have socat run after you restart. So I created the following Property List file (.plist):

Path: ~/Library/LaunchAgents/com.example.phpstorm-docker-bridge.plist

Owner: root

Group: staff


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Then run:

sudo launchctl load com.example.phpstorm-docker-bridge.plist

Now you can follow Jetbrains Confluence page on how to connect PhpStorm with Docker.