xdebug not working in Docker Desktop for Mac

I have the same problem. It might be related to the limitations of docker within OSX. See these links.

https://docs.docker.com/docker-for-mac/networking/ https://forums.docker.com/t/explain-networking-known-limitations-explain-host/15205

Possible workarounds have also been suggested. One of these is to create a device with a new ip (e.g. 10.254.254.254) that loops back to you localhost. When you then use this ip as remote host address instead the one assigned by docker (either 127.0.0.1 or 172.17.0.2), it should do the trick. Follow this link for a coded solution


Change your docker-compose.yml to the below.

You'll want to expose port 9000, not bind. Also update your xdebug ini to the ip of your host (mac) not the ip of docker.

I also added how you can mount the xdebug file from your mac directly to your docker so you can update it on the fly. This allows you more control since you may have to update your ip based of moving from wifi to wifi. The xdebug.remote_host= ip should be your mac local network ip. Just remember if you're on apache to do a service apache2 restart or appropriate command to restart your server any time you change the ip.

version: '2'
services:
  php:
    image: <image name>
    ports:
      - 80:80
    expose:
      - "9000"
    volumes:
      - .:/var/www/html
      - ./php.ini:/usr/local/etc/php/conf.d/php.inivolumes:
      - ./20-xdebug.ini:/etc/php/7.1/cli/conf.d/20-xdebug.ini //obviously you would change this to your correct paths
      - ./20-xdebug.ini:/etc/php/7.1/apache2/conf.d/20-xdebug.ini //obviously you would change this to your correct paths


# 20-xdebug.ini, this is how mine is setup. 
zend_extension = /usr/lib/php/20160303/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=192.168.0.4 // Make sure you use your host (mac) local ip, not the ip of docker. 
xdebug.remote_port=9000
xdebug.idekey = PHPSTORM
xdebug.remote_handler = dbgp
xdebug.remote_autostart = 1
xdebug.remote_log = /var/log/xdebug.log