简体   繁体   中英

Xdebug 3 couldn't connect from Docker [20.10.12] to PhpStorm debug client. Ubuntu

So, my configurations are:

  1. Dockerfile:
FROM php:8.1-apache as php_base
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN a2enmod rewrite && install-php-extensions pgsql
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf && service apache2 restart
WORKDIR /var/www/lessor-calculator

FROM php_base as php_dev
RUN pecl install xdebug && docker-php-ext-enable xdebug
  1. docker-compose.yml:
version: "3.4"

services:
  app:
    build:
      context: docker/server
      target: php_dev
    networks:
      my-network:
    environment:
      PHP_IDE_CONFIG: "serverName=MyApp"
    ports:
      - "${DOCKER_SERVER_PORT:-9180}:80"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ./:/var/www/lessor-calculator
      - ./docker/server/apache/sites-enabled:/etc/apache2/sites-enabled
      - ./docker/server/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
      - ./docker/server/php/conf.d/xdebug.log:/var/log/xdebug.log
      - ./docker/server/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
  1. xdebug_info() output:

xdebug_info_screenshot

  1. PhpStorm settings:

phpstorm_php_interpreter_screenshot

phpstorm_xdebug_settings_screenshot

  1. Xdebug log:
[17] Log opened at 2022-01-04 14:47:45.645181
[17] [Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003.
[17] [Step Debug] WARN: Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).
[17] [Step Debug] ERR: Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(
[17] Log closed at 2022-01-04 14:47:45.649491

Also I've tried to use another port, curl host.docker.internal:9000 , with answer "Connection refused", (but just ping host.docker.internal is work fine). Everyone said, that there's no need to map 9000 port. Please any suggestion, what reason could be. Thank you.

UPDATE: Xdebug conf:

zend_extension=xdebug

[xdebug]
xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.log="/var/log/xdebug.log"

Update: new configuration for 9003 port, enable xdebug.log

Update 2: i'm using rootless docker

Why not expose the desired port with eg. EXPOSE 9003 in Dockerfile ?

xdebug ports and Dockerfile ports need to match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM