dunglas / symfony-docker

A Docker-based installer and runtime for Symfony. Install: download and `docker compose up`.
https://dunglas.dev/2021/12/symfonys-new-native-docker-support-symfony-world/
2.47k stars 733 forks source link

xdebug, Traefik and/or rootless #569

Closed zebba closed 5 months ago

zebba commented 5 months ago

Hey there!

I'm trying to get xdebug running but failed so far.

My general setup is running Traefik in a rootless Docker setup for development.

# traefik/compose.yaml
version: '3'

services:
  reverse-proxy:
    image: traefik:v2.10
    command:
      - "--providers.docker=true"
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    networks:
      - gateway
    volumes:
      - /run/user/1000/docker.sock:/var/run/docker.sock:ro
      - ./ssl:/etc/traefik/ssl:ro
      - ./traefik.yaml:/etc/traefik/traefik.yaml:ro

networks:
  gateway:
    external: true
# traefik/traefik.yaml
tls:
  certificate:
    - certFile: /ssl/some.pem
      keyfile: /ssl/some-key.pem   

providers:
  docker:
    exposedByDefault: false

entryPoints:
  http:
    address: ":80"
  https:
    address: ":443"
  http3:
    address: ":443/udp"

api:
  dashboard: true
  insecure: true
# project/composer.override.yaml
version: "3.7"

# Development environment override
services:
  php:
    build:
      context: .
      target: frankenphp_dev
    volumes:
      - ./:/app
      - ./frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro
      - ./frankenphp/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro
      - ./frankenphp/certs:/etc/caddy/certs:ro
    environment:
      MERCURE_EXTRA_DIRECTIVES: demo
      # See https://xdebug.org/docs/all_settings#mode
      XDEBUG_MODE: "${XDEBUG_MODE:-off}"
      SERVER_NAME: project.localhost
      CADDY_SERVER_EXTRA_DIRECTIVES: "tls /etc/caddy/certs/tls.pem /etc/caddy/certs/tls.key"
      TRUSTED_HOSTS: ^project\.localhost|localhost}|php$$
    extra_hosts:
      - host.docker.internal:host-gateway
    tty: true
    labels:
      - "traefik.enable=true"
      - "traefik.tcp.routers.project.entrypoints=https"
      - "traefik.tcp.routers.project.rule=HostSNI(`*`)"
      - "traefik.tcp.routers.project.tls=true"
      - "traefik.tcp.routers.project.tls.passthrough=true"
      - "traefik.tcp.services.project.loadbalancer.server.port=443"
      - "traefik.udp.routers.project.entrypoints=http3"

networks:
  default:
    name: gateway
    external: true

I've configured Phpstorm according to docs/xdebug.md and used the xdebug browser plugin to send the IDE_KEY but was not able to receive any requests in Phpstorm.

I also ran the Run > Web Server Debug Validation in Phpstorm prompting these warnings:

Pinging of host.docker.internal from inside the php container returns data.

What am I missing?

7-zete-7 commented 5 months ago

Hello @zebba.

Traefik does not forward your original IP to the container. Container's XDebug tries to connect to Traefik's IP instead of your's.

For the container to work correctly, you must use the http Traefik proxying.

More information about this issue: https://community.traefik.io/t/tcp-service-forward-original-ip/17547

maxhelias commented 5 months ago

Thanks @7-zete-7 for your help with this issue