xdebug not working in Docker Desktop for Mac xdebug not working in Docker Desktop for Mac docker docker

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.soxdebug.remote_enable=1xdebug.remote_host=192.168.0.4 // Make sure you use your host (mac) local ip, not the ip of docker. xdebug.remote_port=9000xdebug.idekey = PHPSTORMxdebug.remote_handler = dbgpxdebug.remote_autostart = 1xdebug.remote_log = /var/log/xdebug.log


I've struggled with this for a bit of time and I've found a simpler solution after reading the official documentation at https://docs.docker.com/docker-for-mac/networking/#httphttps-proxy-supportEspecially this part :

I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST

The host has a changing IP address (or none if you have no network access). From 18.03 onwards our recommendation is to connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host. This is for development purpose and will not work in a production environment outside of Docker for Mac.

Once you've understand this you can set the remote_host setting to host.docker.internal in your php.ini inside the container. Also don't forget to set the xdebug.remote_connect_back to 0 the the host settings is not ignored :

xdebug.remote_port=9000xdebug.idekey=PHPSTORMxdebug.remote_log=/tmp/xdebug.logxdebug.remote_host=host.docker.internalxdebug.remote_enable=1xdebug.remote_connect_back=0