Xdebug on Docker doesn't work on M1 Macbook Pro


Docker Desktop (Preview): 0.0.0(1) OS: macOS Big Sur 11.1 IDE: PHPStorm

PHP: 7.2 Xdebug: 2.9.8


Normal Xdebug settings are omitted. The environment that is running on the existing (Intel Macbook) does not work.


The following error occurs in xdebug.log set in php.ini.

[71] Log opened at 2020-12-29 07:57:31
[71] I: Connecting to configured address/port: host.docker.internal:9005.
[71] W: Creating socket for 'host.docker.internal:9000', getaddrinfo: Invalid argument.
[71] E: Could not connect to client. :-(
[71] Log closed at 2020-12-29 07:57:36

Cause and solution

Docker official documentation listed as known issue: sweat:

The DNS name host.docker.internal only works if you add --add-host=host.docker.internal:host-gateway to the docker run command

The DNS name host.docker.internal cannot be used without adding --add-host = host.docker.internal: host-gateway to docker run.

If you do this with docker-compose,

      - "host.docker.internal:host-gateway"

I need to write.

Then, I found the following description in / etc/hosts in the container.    host.docker.internal

It works with this. .. .. It does not become.

E: Time-out connecting to client (Waited: 200 ms). :-(

It seems that the connection times out. .. ..

Apparently the container-> host (Mac) communication is not reaching.

As a result of various trials, it worked when I set host-gateway to my IP!

      - "host.docker.internal:192.168.xxx.xxx"

You can get your own IP on the terminal below.

ipconfig getifaddr en0

Future tasks

This is a solution. .. .. However, usually IP is automatically set by DHCP, and I want to change the IP dynamically. .. ..

Do you want to pack the IP into an environment variable so that it is read at build time, or write a script that rewrites the host in the container? .. ..

Recommended Posts

Xdebug on Docker doesn't work on M1 Macbook Pro
What to do if Docker Desktop fails to launch on your M1 MacBook Pro
Install Docker on Windows 10 PRO
[Memo] Installed on Macbook Pro
Use Docker on your M1 Mac
Check when nvidia-smi on Ubuntu doesn't work
Docker doesn't work after updating Debian systemd
Liberty on Docker
Redmine on Docker
When Kubernetes doesn't start on Docker Desktop for Mac
What to do if TextToSpeech doesn't work on Android 11