You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker环境下VSCode无法连接Xdebug的问题求助

Docker容器中Xdebug与VSCode调试连接问题排查

我在Docker容器中配置Xdebug步进调试器,试图实现VSCode与容器的调试连接,但调试无法生效。主机与容器的端口映射正常(可通过localhost:8080访问Web服务),已关闭防火墙、禁用VPN,仍无法解决问题。

相关配置

1. 项目.vscode目录下launch.json的配置片段

{
    "name": "Xdebug",
    "type": "php",
    "request": "launch",
    "hostname": "127.0.0.1",
    "port": 9000,
    "pathMappings": {
        "/var/www/html/": "${workspaceFolder}/code/",
    },
}

2. docker-compose.yml的配置片段

services: 
  webserver:
    container_name: webserver_orderlinev3
    build: webserver
    ports: 
      - 8080:80
      - 9000:9000
    volumes: 
      - ./code:/var/www/html
      - ./webserver/php-ini-overrides.ini:/usr/local/etc/php/conf.d/php-ini-overrides.ini
      - ./webserver/phpsessions:/var/www/phpsessionfiles
      - ./xdebuglog:/tmp/xdbglog

    extra_hosts:
      - host.docker.internal:host-gateway
    environment:
      - XDEBUG_MODE=debug,develop,coverage,profile,trace

3. php.ini覆盖配置

[session]
session.save_handler=files
session.save_path="/var/www/phpsessionfiles"

[xdebug]
xdebug.client_port=9000
xdebug.mode=off

xdebug.discover_client_host=on
xdebug.client_host = host.docker.internal

xdebug.remote_connect_back=0
xdebug.remote_enable=on
xdebug.remote_handler=dbgp

xdebug.start_with_request = yes
xdebug.log=/tmp/xdbglog/xdebug_remote.log

Xdebug日志内容

[17] Log opened at 2022-10-25 16:22:46.248594
[17] [Step Debug] INFO: Checking remote connect back address.
[17] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[17] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[17] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.29.0.1:9000.
[17] [Step Debug] WARN: Creating socket for '172.29.0.1:9000', poll success, but error: Operation now in progress (29).
[17] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9000. :-|
[17] [Step Debug] INFO: Connected to debugging client: 172.29.0.1:9000 (from REMOTE_ADDR HTTP header), host.docker.internal:9000 (fallback through xdebug.client_host/xdebug.client_port). :-)
[17] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/orderline/api/index.php" language="PHP" xdebug:language_version="8.0.24" protocol_version="1.0" appid="17"><engine version="3.1.5"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2022 by Derick Rethans]]></copyright></init>

[17] [Step Debug] <- feature_set -i 1 -n max_children -v 100
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="max_children" success="1"></response>

[17] [Step Debug] <- feature_set -i 2 -n max_data -v 8192
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_data" success="1"></response>

[17] [Step Debug] <- breakpoint_set -i 3 -t exception -x "Notice"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="170008"></response>

[17] [Step Debug] <- breakpoint_set -i 4 -t exception -x "Warning"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="4" id="170009"></response>

[17] [Step Debug] <- breakpoint_set -i 5 -t exception -x "Error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="5" id="170010"></response>

[17] [Step Debug] <- breakpoint_set -i 6 -t exception -x "Exception"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="6" id="170011"></response>

[17] [Step Debug] <- breakpoint_set -i 7 -t exception -x "Fatal error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="7" id="170012"></response>

[17] [Step Debug] <- breakpoint_set -i 8 -t exception -x "Parse error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="8" id="170013"></response>

[17] [Step Debug] <- breakpoint_set -i 9 -t exception -x "Unknown error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="9" id="170014"></response>

[17] [Step Debug] <- run -i 10
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="10" status="stopping" reason="ok"></response>

[17] Log closed at 2022-10-25 16:22:46.308352

无法从日志中定位调试不生效的原因,恳请有Docker和Xdebug经验的人士帮忙排查。

内容的提问来源于stack exchange,提问作者L00tz1ffer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 17:15:52