Xdebug cannot connect to Docker host

I just installed Docker on my machine and set up the Nginx / PHP7 (FPM) / MySQL setup, but installing Xdebug in a PHP container, I can’t get it to connect to PHPStorm on my host machine.

Here is my PHP Xdebug configuration ...

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts- 20151012/xdebug.so xdebug.remote_log=/usr/local/var/log/xdebug.log xdebug.remote_enable=1 xdebug.remote_host=192.168.99.1 xdebug.remote_port=9000 xdebug.remote_connect_back=1 xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_autostart=true 

When viewing the cookie with the Xdebug installed, there is no connection invitation for the container. If I look at a locally hosted site, there is, so I know that PHPStorm is listening correctly.

On the local machine, I can connect to port 9000 ...

 $ telnet 192.168.99.1 9000 Trying 192.168.99.1... Connected to 192.168.99.1. Escape character is '^]'. ^] telnet> quit Connection closed. 

... however, I can neither from the boot VM, nor from the container. When I try, he sits there, doing nothing. However, both the virtual machine and the container can ping the host machines just fine.

I tried disabling the Mac firewall, but still not fun.

I'm not quite sure how to disable the firewall on VM2 boot2docker.

Any insight into why this will not work would be greatly appreciated. Thanks in advance.

+2
source share
2 answers

Xdebug is recommended to be configured inside the container:

 zend_extension = xdebug.so xdebug.remote_enable = 1 xdebug.remote_connect_back = 0 xdebug.remote_host = docker.for.mac.localhost xdebug.remote_port = 9000 xdebug.remote_handler = dbgp xdebug.remote_mode = req xdebug.remote_autostart = 1 xdebug.idekey = PHPSTORM 

With Docker-17.06, you can access services hosted on a Mac inside Container through a static hostname: docker.for.mac.localhost

DO I WANT TO CONNECT WITH THE CONTAINER TO THE SERVICE FOR THE HOST?
Your Mac has a changing IP address (or not if you don’t have network access). Starting on June 17, our recommendation is to connect to a Mac-specific DNS name. Docker.for.mac.localhost, which resolves the internal IP address used by the host.

see https://docs.docker.com/docker-for-mac/networking/#i-cannot-ping-my-containers

+1
source

You need to use a network that connects to the Docker host on your Mac. Make ifconfig on Mac and find the local IP address in other local networks, for example 10.0.1.13 . (The specification may differ in version of Docker, but it worked with Vagrant as the Docker host and should work for most virtual machines.)

0
source

Source: https://habr.com/ru/post/1233354/


All Articles