xdebug error message „Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003“ in docker

I got this error message in docker log output:

Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003

I could not connect xdebug in phpstorm. I checked port config, it is correct. But I am not sure, where the message „host.docker.internal“ come from. Until I found here:

https://github.com/docker/for-linux/issues/264#issuecomment-381437057

and

https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container/43541732#43541732

So I add following config in my compose.yml for web server.

...
 extra_hosts:
      - "host.docker.internal:192.168.2.193"
...

After rebuild the image, you can check your hosts file in container. It has a new line in /etc/hosts, like

192.168.2.193 host.docker.internal

This is IP from my host, on that is runing phpstorm with listen to port 9003. And it works. Of course you must install xdebug and enbalbe it first. And check your php.ini the section:

[xdebug]
xdebug.mode=coverage
xdebug.client_host=localhost
xdebug.client_port=9003
xdebug.start_with_request=yes