Skip to content

Debugging into devcontainer #97

@Ninitage

Description

@Ninitage

Hi,

Context: I'm failing to start a debugging session into a Zed editor instance attached to a running devcontainer.

Host: Arch Linux system
Zed version: 0.219.4+stable (installed through pacman)
Zed PHP extension version: 0.4.6 (installed from zed extension menu)
Docker version: 29.1.4, build 0e6fee6c52
Docker Compose version: 5.0.1
devcontainer-cli version: 0.80.3 (installed from AUR)

Dev container is composed of a docker compose file. The micro service used for php is based on FrankenPHP, PHP v8.3 onto a Debian Bookworm system. Xdebug is installed and configured on it.

devcontainer.json

{
    "name": "my app",
    "dockerComposeFile": [
        "../docker-compose.yaml",
        "../docker-compose.override.yaml"
    ],
    "service": "app",
    "workspaceFolder": "/app",
    "remoteEnv": {
        "XDEBUG_MODE": "debug",
        "XDEBUG_CONFIG": "client_host=host.docker.internal client_port=9003"
    },
    "customizations": {
        "zed": {
            "extensions": ["php"]
        }
    }
}

docker-compose.yaml

services:
  app:
    build:
      context: ./
      dockerfile: ./Dockerfile
    # restart: always
    ports:
      - "80:80" # HTTP
      - "443:443" # HTTPS
    volumes:
      - ./:/app
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      - db
      - messenger
    networks:
      - db
      - messenger

  db:
    image: amd64/mariadb:11.8.3
    ports:
      - "3306:3306"
    environment:
      MARIADB_USER: "user"
      MARIADB_PASSWORD: "password"
      MARIADB_ROOT_PASSWORD: "root-password"
      MARIADB_DATABASE: "my_database"
    networks:
      - db

  messenger:
    image: amd64/redis:8.2-bookworm
    networks:
      - messenger

volumes:
  caddy_data:
  caddy_config:

networks:
  db:
    driver: bridge
  messenger:
    driver: bridge

docker-compose.override.yaml

services:
    app:
        tty: true
        extra_hosts:
            - "host.docker.internal:host-gateway"

Dockerfile

FROM dunglas/frankenphp:1.9.1-builder-php8.3.25-bookworm
WORKDIR /app
RUN set -eux \
    && install-php-extensions \
    @composer \
    apcu \
    intl \
    gd \
    opcache \
    openssl \
    pdo_mysql \
    redis \
    xdebug \
    zip \
    && cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini \
    && sed -i "s/memory_limit = 128M/memory_limit = 256M/g" /usr/local/etc/php/php.ini \
    && echo "xdebug.mode=debug,develop" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo 'xdebug.client_host="host.docker.internal"' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.discover_client_host=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo 'xdebug.log="/app/var/log/xdebug.log"' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

.zed/debug.json

[
    {
        "label": "PHP: Listen to Xdebug",
        "adapter": "Xdebug",
        "request": "launch",
        "port": 9003,
        "hostname": "127.0.0.1",
        "pathMappings": {
            "/app": "$ZED_WORKTREE_ROOT"
        },
        "log": true
    },
    {
        "label": "PHP: Debug this test",
        "adapter": "Xdebug",
        "request": "launch",
        "port": 9003,
        "hostname": "127.0.0.1",
        "program": "vendor/bin/phpunit",
        "args": ["--filter", "$ZED_SYMBOL"],
        "pathMappings": {
            "/app": "$ZED_WORKTREE_ROOT"
        },
        "log": true
    }
]

remote php xdebug extension is installed into /data/zed/remote_extensions/work/php/Xdebug/Xdebug_v1.39.1/extension/ into the dev container.
LSP is working.

Process

  1. I start the project running the command devcontainer up --workspace-folder /home/user/my_app.
  2. I launch Zed editor.
  3. I click on yes into this popup:
Image
  1. Once inside, I try to start a new debug session, the first one listed into the configuration above for example.

Result

  • failing almost instantly
  • debug console is showing:
error: 
error: process exited before debugger attached.
  • no logs are written where it should be defined or into the related button "Open Debug Adapter Logs"
  • host does not seem to listen on port 9003 using the command ss -lntp | grep 9003 to check it (firewall rules have been added to make sure, even disabled, it does not change anything, not sure it's related and not sure host should be listening here, correct me if I'm wrong)

I've watched most related issues onto Zed repository and this one, tried different configurations, like replacing the ip address into .zed/debug.json by 0.0.0.0 or "host.docker.internal", tried another port even if most people seems to discourage it, make sure the log file have full permission access to get more info about what is going on without any success. Let Xdebug discover host does not help either.

So, I would like to know if anyone has noticed an error into my configuration please? (the same one on another computer seems to work well with another editor, but I really would like to switch to Zed, seems promising)
Or did I miss something? Maybe debugging into a devcontainer is not implemented yet?

Edit

I've succeeded to get some logs:

[140475505965760] Log opened at 2026-01-19 23:02:02.736359
[140475505965760] [Config] INFO: Control socket set up successfully: '@xdebug-ctrl.140475505965760'
[140475505965760] [Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003.
[140475505965760] [Step Debug] WARN: Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).
[140475505965760] [Step Debug] ERR: Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port).
[140475505965760] Log closed at 2026-01-19 23:02:02.737016

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions