Remote Debugging with XDebug from inside a Docker Container does not work

docker xdebug
docker-php-ext-install xdebug
phpstorm xdebug docker mac
xdebug log
xdebug - docker wordpress
docker xdebug proxy
php enable xdebug
xdebug_remote_host docker

I'm trying to setup a dockered AMP environment and can't get the remote debugger working. My setup is as follows:

I have a database container running mysql which is working like a charm. I built a Docker image 'phpmysqli' with the following Dockerfile

FROM php:apache

RUN docker-php-ext-install mysqli mbstring

# zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/
RUN pecl install xdebug
RUN echo 'zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20131226/' >> /usr/local/etc/php/php.ini
RUN touch /usr/local/etc/php/conf.d/xdebug.ini; \
    echo xdebug.remote_enable=1 >> /usr/local/etc/php/conf.d/xdebug.ini; \
    echo xdebug.remote_autostart=0 >> /usr/local/etc/php/conf.d/xdebug.ini; \
    echo xdebug.remote_connect_back=1 >> /usr/local/etc/php/conf.d/xdebug.ini; \
    echo xdebug.remote_port=9000 >> /usr/local/etc/php/conf.d/xdebug.ini; \
    echo xdebug.remote_log=/tmp/php5-xdebug.log >> /usr/local/etc/php/conf.d/xdebug.ini;

RUN echo 'date.timezone = Europe/Berlin' > /usr/local/etc/php/conf.d/date.ini

I call

docker run --rm -ti  --name web -p -v /path/to/projects:/var/www/html --link db:db  phpmysqli

After this phpinfo respectively php -i shows that xdebug 2.3.2 is up and running.

Next I setup a Server inside IntelliJ IDEA called 'Docker' with Host, Port 8080 and Debugger Xdebug. I setup the path mapping analogous to the Volume mapping in the docker run statement.

In the PHP->Debug settings I checked that I use port 9000 for incoming connections, that I will accept external connections and that I will not ignore connections from unregistered servers.

After this I created a new PHP Remote Debug Configuration called Docker, too. Server is Docker, session id is XDEBUG_IDEA.

I can call PHP files on the Container, I can connect to the db via the link... but for some reason nothing whatsoever happens when I try to start a debug session. I tried using a cookie (and yes, I set XDEBUG_IDEA as session id in xdebug helper). I tried sending XDEBUG_SESSION_START=XDEBUG_IDEA as GET...

Can you smart people out there tell me what I missed?

You can try with this configuration. php-apache build provide two method to compile and enable module php. It's nicer to use docker-php-ext-enable xdebug to set correct file configuration.

FROM php:5.4-apache

# Enable and configure xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN sed -i '1 a xdebug.remote_autostart=true' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_mode=req' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_handler=dbgp' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_connect_back=1 ' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_port=9000' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_host=' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN sed -i '1 a xdebug.remote_enable=1' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

Debug PHP in Docker with PHPStorm and Xdebug · GitHub, Do you have any idea how debug cli command in docker container? Copy link Enable Remote xdebug echo "xdebug.idekey = PHPSTORM" Sounds silly but if it is not working for you, restart your Docker containers and your IDE. I had all  After executing that command from your Docker container with Xdebug enabled PHP server the debugger (on your computer) should/may exit (like my vdebug does), which means that it receives some message. This behavior will confirm that port number 9000 and IP address are correct choice and should be used in Xdebug configuration.

For me on a PHP, NGINX Docker environment using sublime, I got it to work with these settings:

xdebug.remote_enable = 1
xdebug.remote_mode = req
xdebug.remote_port = 9001

The one that took me forever to figure out was to set the remote_host to host.docker.internal.

Debugging PHP (web and cli) with Xdebug using Docker and , In my example, I will use a Docker image of TheCodingMachine created by David Négrier. If you are starting a (8) Don't forget to click on Use path mappings A new windows should open and you should access to PHPStorm debug bar. Debug (1) Click on for openning the remote PHP interpreter. In ‘pathMappings’, the left part is path in Docker container, and the right part is the path on your local machine. Xdebug will need a port (usually it runs on 9000), please make sure the port

close: xdebug.remote_connect_back=0 add: xdebug.remote_host=[your docker host/machine IP]

Configure remote debugging with XDebug for php docker container , If you want to set up remote debug from your container you have 2 options: 1. But the docker0 interface is not available for Docker in macOS. Btw if you need to get a shell of the VM that was created by HyperKit run: Configuramos o xdebug utilizando a chave (XDEBUG_CONFIG), precisamos então configurar o remote_host que vai receber como valor o endereço de IP da rede do Docker. E para o PHPStorm utilizaremos a chave (PHP_IDE_CONFIG), precisamos configurar uma variavél de ambiente "serverName" que será a conexão que a IDE vai escutar o xdebug.

If you don't want do change xdebug config in the container and want to make it work using xdebug.remote_connect_back=1 you can set the HTTP-Header X-Forwarded-For to the IP of host.docker.internal und thus defines PHP $_SERVER['HTTP_X_FORWARDED_FOR'] which xdebug prefers and uses as the client IP instead of $_SERVER['REMOTE_ADDR'].

Remote debugging a Java Application running in Docker container , I've learnt it the hard way that not every bug in your code can be Remote debugging a Java Application running in Docker container with Intellij Idea Goto Run > Debug and select the configuration that we just created. Also, host.docker.internal is a reserved host entry for Docker for Windows and Mac to allow a container to communicate with the host — if you set this to localhost then XDebug will not be able

Debugging within a PHP Docker Container using IDEA/PhpStorm , But how can we debug the PHP code running in the container? In this RUN echo 'zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-​20151012/ Create a Run Configuration of the type “PHP Remote Debug”. For more details, please look at this TheCodingMachine Docker PHP images. (1) Enable the Xdebug extension (2) If you are using a different Xdebug port, set your custom Xdebug port (3) Add your Xdebug server name (4) If you are using the default Xdebug port, please remove remote_port=[your_xdebug_port]. Otherwise, add your custom Xdebug port

Debug an app running in a Docker container, Debug an app running in a Docker container, using Visual Studio Code. into launch.json is not sufficient to build and debug a Docker container. To successfully run a Docker launch configuration, you must have: pathMappings, Maps the project path between local machine and remote host. projectType  PhpStorm will now try to create the container and figure out if it can run PHP. If all goes well, you should see the following screenshot with information about the PHP and Xdebug versions in the image/container. Note: Sometimes, this does not work immediately. If that's the case for you, try to click the "Refresh" icon next to "PHP executable".

How to setup PhpStorm with Xdebug on Docker [Tutorial Part 2 , Your browser does not currently recognize any of the video formats available. Setup: The docker containers; Run PHP via built-in Docker setup in PhpStorm; Configure Docker PHP CLI Interpreter; Run/debug a php script on docker sign on the top left and choose "From Docker,Vagrant,VM,Remote". you are missing port :9000 (or :9001) in the docker-compose.yml,. which needs to be connectable, for the IDE to connect from the outside. for VSCode the PHP Debug extension might be required to interact with xdebug.

  • No idea what is wrong, but you should connect in your container with a docker exec -it web_id bash and debug inside, as you would on any Linux server with such an issue
  • are you on Windows? If yes what are you using for your Docker host? (vagrant, other?)
  • I'm running Ubuntu 15.04
  • a workaround to try out: start your container with docker run --net=host (and remove -p This will make your container and your Docker host share the same network interface. As such from the container point-of-view, localhost will be the Docker host. xdebug might have less trouble figuring out how to connect to the debugger
  • This is not compatible with --link
  • I've tried "pecl install xdebug" and it returns an error: pecl/xdebug requires PHP (version >= 5.5.0), installed version is 5.4.45 No valid packages found install failed
  • I have the same error. I changed "FROM php:5.4-apache" to "FROM php:7.0-apache" and it resolved my issue :)
  • host.docker.internal will only work for Docker for Windows or Docker for Mac and not available for Docker running in linux environments.…
  • Thank you! Your config works perfectly!