Search code examples
phpdockerdocker-composephpstormxdebug

XDebug. Docker. Can't disable an autostart


I'm working with Docker through the docker-compose commands. I want to be able to run my app both in a debug and a normal mode, but now the debugger starts anyway.

I have such an app.docker file.

FROM php:7-fpm

RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client \
    && docker-php-ext-install mcrypt pdo_mysql

RUN yes | pecl install xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /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.idekey=PHPSTORM" >> /usr/local/etc/php/conf.d/xdebug.ini

WORKDIR /var/www

If i click "Run"

enter image description here

The debug session starts anyway

enter image description here

I want to be able both to run and debug my tests (and the rest of the app). Do I miss something obvious?


Solution

  • It's an unexpected xdebug remote host behavior.

    I have fixed it with stopping using an environment variable.

    In my docker-compose.yml

    app:
            ...
            environment:
                ...
                # removed the line below
                XDEBUG_CONFIG: remote_host=docker.for.mac.localhost
           ...
    

    And added it to the docker file. Something like

    RUN yes | pecl install xdebug \
        ... 
        && echo "xdebug.remote_host=docker.for.mac.localhost" >> /usr/local/etc/php/conf.d/xdebug.ini \
    

    More about it could be read at this blog post. It's creator gave an idea for my solution and we have updated the article.