How to get xdebug working with Docker for Mac

The problem with Docker for Mac and xDebug is that it is mapped to your localhost (, so PHP/xDebug doesn’t actually know the true IP address of the remote host connecting to xdebug. To get around this what we need to do is configure an alias to the loopback device to get this work.

sudo ifconfig lo0 alias

Your xdebug configuration should then also include the following:

xdebug.remote_enable = 1
xdebug.remote_port = 9000

To persist the loopback address, you can create a plist, which will be loaded automatically when you boot your mac:

Filename: /Library/LaunchDaemons/com.ralphschindler.docker_10254_alias.plist

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

To run this straightaway (without a reboot) run the following:

launchctl load /Library/LaunchDaemons/com.ralphschindler.docker_10254_alias.plist

Credit goes to @ralphschindler for this epic gist: Docker (Mac) De-facto Standard Host Address Alias

Previous Post
Next Post
Ash Smith - Freelance Magento Developer

I'm Ash, a Magento 2 Developer @ Play Sports Network, keen cyclist and aspiring triathlete. With over ten years Magento experience.

Need a hand with something? Contact me