我有以下Dockerfile:
FROM php:7.0-fpm-alpine
RUN apk add --update --virtual build_deps gcc g++ autoconf make &&\
docker-php-source extract &&\
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.remote_connect_back=1" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
echo "xdebug.remote_handler = dbgp" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
echo "xdebug.remote_mode = req" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
docker-php-ext-enable xdebug &&\
docker-php-source delete && \
apk del build_deps && \
rm -rf /var/cache/apk/* && \
rm -rf /tmp/*
ENTRYPOINT ["php-fpm"]
我使用以下docker-compose.yml
运行它:
version: '2'
services:
nginx_dev:
image: nginx:alpine
ports:
- "5092:5092"
links:
- "my_symfony_www_dev"
volumes:
- './conf/nginx/nginx_dev.conf:/etc/nginx/nginx.conf:ro'
- './logs/dev:/var/logs'
volumes_from:
- 'my_symfony_www_dev'
my_symfony_www_dev:
build:
context: .
dockerfile: Dockerfile_dev
image: "myimage/my_symfony_app:dev_php"
volumes:
- "$SOURCE_PATH:/var/www/html:Z"
environment:
- PHP_IDE_CONFIG= "serverName=my_symfony_www_dev"
- XDEBUG_CONFIG="remote_host=10.254.254.254,remote_port=9080"
- PHP_XDEBUG_ENABLED=1
另见there我跑:
sudo ip addr add 10.254.254.254/24 brd + dev enp4s0 label enp4s0:1
并配置了PhpStorm IDE:
然后在Firefox中我按下按钮,在PhpStorm中我按下按钮我在app_dev.php
上设置断点,没有任何反应。
我的系统通过9080
命令监听端口netstat -ntlp
,其中PhpStorm监听(PhpStorm是根据that answer的服务器)。
tcp 0 0 0.0.0.0:9080 0.0.0.0:* LISTEN 4773/java
您是否知道为何会发生这种情况以及如何解决这个问题?
phpinfo()
显示:
我还将de cocker-compose.yml设置为:
version: '2'
services:
nginx_dev:
image: nginx:alpine
ports:
- "5092:5092"
links:
- "my_symfony_www_dev"
volumes:
- './conf/nginx/nginx_dev.conf:/etc/nginx/nginx.conf:ro'
- './logs/dev:/var/logs'
volumes_from:
- 'my_symfony_www_dev'
my_symfony_www_dev:
build:
context: .
dockerfile: Dockerfile_dev
image: "myimage/my_symfony_app:dev_php"
volumes:
- "$SOURCE_PATH:/var/www/html:Z"
environment:
- XDEBUG_CONFIG="remote_host=10.254.254.254,remote_port=9080"
- PHP_XDEBUG_ENABLED=1
我的dockerfile是:
FROM php:7.0-fpm-alpine
RUN apk add --update --virtual build_deps gcc g++ autoconf make &&\
docker-php-source extract &&\
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.remote_connect_back=0" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
echo "xdebug.remote_handler = dbgp" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
echo "xdebug.remote_mode = req" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
docker-php-ext-enable xdebug &&\
docker-php-source delete && \
apk del build_deps && \
rm -rf /var/cache/apk/* && \
rm -rf /tmp/*
ENTRYPOINT ["php-fpm"]
结果相同。
答案 0 :(得分:2)
最后,我必须将以下内容放在Dockerfile
上:
FROM php:7.0-fpm-alpine
VOLUME /var/log/xdebug
ARG XDEBUG_HOST="172.17.0.1"
ARG XDEBUG_PORT=9021
RUN apk add --update --virtual build_deps gcc g++ autoconf make &&\
docker-php-source extract &&\
pecl install xdebug &&\
docker-php-ext-enable xdebug &&\
&& 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_handler = dbgp" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
echo "xdebug.remote_mode = req" >> /usr/local/etc/php/conf.d/xdebug.ini &&\
echo "xdebug.remote_host=${XDEBUG_HOST}" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&\
echo "xdebug.remote_port=${XDEBUG_PORT}" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini &&\
docker-php-source delete && \
apk del build_deps && \
rm -rf /var/cache/apk/* && \
rm -rf /tmp/*
ENTRYPOINT ["php-fpm"]
XDEBUG_HOST
build arg包含GNU / Linux系统上docker0
网络接口的ip(使用ifconfig
查找)。
在我的docker-compose.yml
上,我提供了以下内容:
version: '2'
services:
nginx_dev:
image: nginx:alpine
ports:
- "5092:5092"
links:
- "my_symfony_www_dev"
volumes:
- './conf/nginx/nginx_dev.conf:/etc/nginx/nginx.conf:ro'
- './logs/dev:/var/logs'
volumes_from:
- 'my_symfony_www_dev'
my_symfony_www_dev:
build:
context: .
dockerfile: Dockerfile_dev
args:
XDEBUG_HOST: 172.17.0.1
XDEBUG_PORT: 9021
image: "myimage/my_symfony_app:dev_php"
volumes:
- "$SOURCE_PATH:/var/www/html:Z"
在./conf/nginx/nginx_dev.conf
映射到卷上时,我在server
部分添加了以下设置:
server_name 0.0.0.0;
然后在phpstorm上使用以下设置:
然后你很高兴去!