【问题标题】:Xdebug 3 doesn't connect in dockerXdebug 3 未在 docker 中连接
【发布时间】:2021-05-26 18:11:36
【问题描述】:

我将这个 docker-compose 文件与 Xdebug 选项一起使用,这些选项在本地 Xdebug 安装中对我有用,但在 Docker 中不起作用。

version: '3'

services:
    app:
        container_name: php7.3-xdebug
        image:  'php7.3-xdebug-i'
        ports: 
            - '9090:80'
        build:
            context: ./
            dockerfile: ./dockerfile
        volumes:
            - ./:/var/www/html
        environment:
            XDEBUG_CONFIG: zend_extension=xdebug.so xdebug.mode=debug xdebug.start_with_request=yes xdebug.client_host=host.docker.internal

这是 Dockerfile:

FROM php:7.3.28-apache-buster
RUN pecl install xdebug-3.0.4 \
    && docker-php-ext-enable xdebug
COPY . /var/www/html
WORKDIR /usr/src/myapp

VSCode 中的这个 launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html": "${workspaceFolder}",
             },
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003
        }
    ]
}

我尝试了很多配置,但没有办法让它工作。

【问题讨论】:

    标签: docker visual-studio-code xdebug


    【解决方案1】:
    XDEBUG_CONFIG: zend_extension=xdebug.so xdebug.mode=debug
        xdebug.start_with_request=yes xdebug.client_host=host.docker.internal
    

    此行不正确:

    1. 您无法通过特定于 Xdebug 的环境变量加载扩展(但您的 Dockerfile 中的 docker-php-ext-enable xdebug 行应该已经解决了这个问题)。
    2. 如果你想通过XDEBUG_CONFIG设置设置,那么你应该不在它们前面加上xdebug.,这在documentation中有解释。
    3. 文档还说只能通过XDEBUG_CONFIG 设置一组选定的设置,而start_with_request 不是其中之一。需要在 PHP ini 文件中设置。
    4. 要设置 Xdebug 的模式,您需要改用XDEBUG_MODE 环境变量,如documentation again 中所述。

    【讨论】:

      猜你喜欢
      • 2019-06-23
      • 2021-02-25
      • 1970-01-01
      • 2021-07-31
      • 1970-01-01
      • 2020-08-10
      • 1970-01-01
      • 2022-01-10
      • 2020-02-19
      相关资源
      最近更新 更多