PHP xdebug3 with Docker in Ubuntu 20.04 does not work

Asked

Viewed 58 times

1

Good afternoon Devs all right, I’m having trouble trying to run Xdebug with Docker on Ubuntu 20.04. Below follows my config.

Docker-Compose.yml

version: '3.7'

networks:
  supervisao:

services:
  nginx:
    image: nginx:stable-alpine
    container_name: supervisao-web
    ports:
      - "80:80"
    volumes:
      - .:/var/www/html/
      - ./.docker/web/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
      - mysql
    networks:
      - supervisao
  mysql:
    image: mysql:latest
    container_name: supervisao-db
    restart: unless-stopped
    tty: true
    ports:
      - "3306:3306"
    volumes:
      - ./.docker/mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: supervisao
      MYSQL_USER: user
      MYSQL_PASSWORD: pass
      MYSQL_ROOT_PASSWORD: pass
      SERVICES_TAGS: dev
      SERVICES_NAME: mysql
    networks:
      - supervisao
  php:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: supervisao-php
    volumes:
      - .:/var/www/html/
      - ./.docker/php/docker-xdebug.ini:/usr/local/etc/php/conf.d/php-docker.ini
    ports:
      - "9000:9000"
    networks:
     - supervisao
  redis:
    image: redis:latest
    volumes:
      - ./.docker/redis:/data
    ports:
      - 6379:6379
    networks:
      - supervisao

.ini

# File: docker-xdebug.ini
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so
xdebug.discover_client_host=1
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003
xdebug.log = /var/www/html/xdebug.log

Launch.json

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

If anyone has ever been through the same problem and can help.

  • You would have to see the log to try to locate the error, but taking a look at your Docker-Compose I think your network configuration is wrong, Voce must specify the drive. So my suggestion is that Voce colocque driver: bridge below the network name.

  • @Rafaelcosta thanks for the feedback, would have an example of how to specify the driver in Compose??

  • I put an example there in the answer, see that I declared the network at the end of the file.

1 answer

0

This is an example of a Docker-Compose with two networks, a bridge and an external one, in your case you can test how to bridge.

version: '3'

services:
  app:
    build: .
    entrypoint: ./.docker/entrypoint.sh
    container_name: catalog-app
    ports:
      - 3001:3000
    environment:
      - HOST=0.0.0.0
    volumes:
      - .:/home/node/app
    networks:
      - app-network
      - rabbitmq_catalog-network

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
    container_name: catalog-elasticsearch
    environment:
      - node.name=elasticsearch
      - cluster.name=elasticsearch-docker-cluster
      - cluster.initial_master_nodes=elasticsearch
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - app-network

  kibana:
    image: docker.elastic.co/kibana/kibana:7.10.1
    ports:
      - 5601:5601
    networks:
      - app-network

networks:
  app-network:
    driver: bridge
  rabbitmq_catalog-network:
    external: true
volumes:
  esdata01:
    driver: local
  • Rafael even putting the driver did not work, the funniest that the same config runs in windows without problems. Thanks for Ajdua

  • It is complicated without the log because it can be several things, for example a port like this can be in use, it is better to run a Docker ps to get the id of the containers and run a Docker logs ID and analyze the logs to try to locate the error. If you want to put the logs here I can see if I can find out

Browser other questions tagged

You are not signed in. Login or sign up in order to post.