After I switched from Docker Machine to Docker for Mac, xdebug stopped working for me. The problem is that port 9000 on the host is not accessible from the container.
Xdebug configuration:

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

In the logs the following:

 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. :-( 

The container in which xdebug is installed is launched using Docker Compose
docker-compose.yml :

 version: '2' services: php: image: <image with php and xdebug> ports: - 80:80 # - 9000:9000 volumes: - .:/var/www/html - ./php.ini:/usr/local/etc/php/conf.d/php.ini - ./xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini 
  • Can you show docker configs? - Andrei Talanin
  • one
    By default, all ports are closed in the docker. Therefore, if you need a port, you should clearly indicate. Most likely you just need to add ports ports: - 80:80 - 9000: 9000 - KoVadim
  • @AndreyTalanin added docker-compose.yml - Shubnikov Alexey
  • most likely, someone uses it. But who prevents another server from using a host machine? In the configuration of the ports of the composer it is not necessary to specify the same ports. - KoVadim
  • @KoVadim, this is how I worked on the Docker Machine. Now on the Docker for Mac, when I add 9000: 9000, the xdebug client (in my case IDE PhpStorm) cannot start listening to this port, cursing that it is busy - Shubnikov Alexey

1 answer 1

My problem was that in Docker for Mac there was no ability to connect to the host from the container. This is probably due to the limitations of docker in OSX. Here you can find more detailed information on this problem and a solution .