macosdockerxdebugdocker-for-macdocker-desktop

xdebug not working in Docker Desktop for Mac


After i switched from Docker Machine to Docker Desktop for Mac, xdebug has stopped working. Port 9000 on the host is unreachable from container with xdebug.
php.ini:

xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_host=172.18.0.1
xdebug.idekey=PHPSTORM

docker-compose.yml:

version: '2'
services:
  php:
    image: <image name>
    ports:
      - 80:80
    # - 9000:9000
    volumes:
      - .:/var/www/html
      - ./php.ini:/usr/local/etc/php/conf.d/php.ini

xdebug.log:

I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 172.18.0.1:9000.
E: Could not connect to client. :-(

Нow to solve my problem ?


Solution

  • 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