To debug Magento CLI running in Docker container run the CLI command with following syntax:
XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_connect_back=0 idekey=PHPSTORM" PHP_IDE_CONFIG="serverName=Docker" bin/magento
To understand better this construct, let's deconstruct it:
XDEBUG_CONFIG=
tells interpret, that you're about to inject some variablesremote_enable=1
enables the remote debuggingremote_mode=req
remote_port=9000
port to listen (change if you use different one)remote_connect_back=0
idekey=PHPSTORM
IDE key to filter connections (change if you use different one)PHP_IDE_CONFIG="serverName=Docker"
enables PHPStorm to use specified server setting