1

I've been struggling with this for some time and here I am :-)

I have a php container with xdebug installed in a Ubuntu 20.04 laptop:

  rest-example-php-8:
    container_name: rest-php
    build: ./docker/php/
    expose:
       - 9000
    depends_on:
      - rest-example-mysql
      - rest-example-redis
    volumes:
      - .:/var/www/html
      - ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
      - ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
    extra_hosts:
      - "host.docker.internal:host-gateway"

The build file:

FROM php:8.0-fpm

RUN pecl install xdebug \
    && docker-php-ext-enable xdebug

And the xdebug configuration

[xdebug]
xdebug.mode=debug
xdebug.client_port=9003
xdebug.start_with_request=yes
xdebug.discover_client_host=true
xdebug.client_host=host.internal.docker
xdebug.idekey=PHPSTORM
xdebug.log = "/var/log/xdebug.log"
xdebug.output_dir = "/var/log/profiler"

When I try to execute any php script either with phpstorm or direcly in the container with bash I get this error:

Xdebug: [Step Debug] Could not connect to debugging client. Tried: fe80:0:0:0:e898:eeff:fefb:e968%vetha93964b:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(

That's with PHP storm, if I do it directly in the container:

Could not connect to debugging client. Tried: host.internal.docker:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(

Things that I've tried:

  1. Change client host. I've tried ips and hostnames, no success

  2. Open my 9003 port in my host machine, according to nmap is open:

    nmap localhost Starting Nmap 7.80 ( https://nmap.org ) at 2021-08-04 19:53 CEST Nmap scan report for localhost (127.0.0.1) Host is up (0.000061s latency). Not shown: 998 closed ports PORT STATE SERVICE 631/tcp open ipp 9003/tcp open unknown

  3. I also checked that is PHP Storm who is listening

sudo lsof -i -P -n | grep LISTEN | grep 9003
java       4566      myuser   54u  IPv6 543552      0t0  TCP *:9003 (LISTEN)

And the problem seems to be in the host machine, I also tried to access the 9003 of the host from the container with no success.

Anyone knows what can be going on and what else could I test? Any help would be much appreciated :-)

1 Answer 1

1

I found the problems myself... I was missing the network configuration in my docker-composer.yaml file, I added and now it looks like so:

version: '3.7'

services:

  rest-mysql:
    container_name: rest-mysql
    image: mysql:latest
    environment:
      MYSQL_DATABASE: gotrendier
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
    networks:
      - go-rest.local
    ports:
      - "3307:3306"

  rest-php-8:
    container_name: rest-php
    build: ./docker/php/
    expose:
       - 9000
    networks:
      - go-rest.local
    volumes:
      - .:/var/www/html
      - ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
      - ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
    extra_hosts:
      - "host.internal.docker:host-gateway"

  nginx:
    container_name: rest-nginx
    image: nginx
    restart: unless-stopped
    networks:
      - go-rest.local
    volumes:
      - ./docker/nginx/.htpasswd:/etc/nginx/.htpasswd:ro
      - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./docker/nginx/config:/etc/nginx/conf.d:ro
      - ./:/var/www/html
    ports:
      - "80:80"

  rest-redis:
    container_name: rest-redis
    image: redis:alpine
    networks:
      - go-rest.local
    ports:
      - "6380:6379"

networks:
  go-rest.local:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .