【发布时间】:2016-10-02 10:48:20
【问题描述】:
问题
我无法在 macOS 上使用 Dockerized 容器中的 Xdebug 进行调试。
我已经非常仔细地阅读了:XDebug Remote configuration、 Nikita Nikitin post 以及 Stackoverflow 和 Github 上提出的所有解决方案。我还是被屏蔽了..
在容器中
我可以连接到容器bash -c "clear && docker exec -it DockerizedSample sh"
它确认 XDebug 已安装。
# php -m -c
[PHP Modules]
Core
...
xdebug
...
[Zend Modules]
Xdebug
而且它的配置似乎是有效的。
# tail /usr/local/etc/php/conf.d/xdebug.ini
xdebug.idekey=PHPSTORM
xdebug.remote_host=172.17.0.1
xdebug.remote_enable=1
xdebug.remote_mode=req
xdebug.remote_port=9000
xdebug.remote_autostart=0
xdebug.remote_connect_back=0
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
泊坞窗文件
FROM bartlebys/php-apache-mongo:latest
MAINTAINER Benoit Pereira da Silva <https://pereira-da-silva.com>
COPY /html /var/www/html/
################################
## CONFIGURE AND ENABLE XDEBUG #
################################
#Erase the current Configuration of xdebug
RUN echo "" > /usr/local/etc/php/conf.d/xdebug.ini
#Configure XDEBUG
RUN HOST_IN_CONTAINER_IP=$(/sbin/ip route|awk '/default/ { print $3 }')\
&&echo "xdebug.idekey=PHPSTORM" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_host=$HOST_IN_CONTAINER_IP" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_mode=req" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_port=9000" >> /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
# Enable XDEBUG's extension
RUN echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" >> /usr/local/etc/php/conf.d/xdebug.ini
运行脚本
#!/bin/sh
# Stop the container
echo "Stop "
docker stop DockerizedSample
# Delete the container
echo "Remove "
docker rm DockerizedSample
# Delete the image if necessary
docker rmi dockerizedsampleimage:latest
# Build the youdubserver image
echo "Building with the current source"
docker build -t dockerizedsampleimage:latest .
# Run DockerizedSample container
echo "Run container "
# Run the container once.
# then grab the IP of the HOST in the container
# stop and relaunch with the good IP
docker run -d --name DockerizedSample dockerizedsampleimage
HOST_IN_CONTAINER_IP=$(docker exec DockerizedSample /sbin/ip route|awk '/default/ { print $3 }')
docker stop DockerizedSample
docker rm DockerizedSample
# Run the debuggable container
docker run -e PHP_IDE_CONFIG="serverName=Dockerized"\
-e XDEBUG_CONFIG="remote_host=$HOST_IN_CONTAINER_IP"\
-p 27017:27017 \
-p 8001:80\
-d --name DockerizedSample dockerizedsampleimage\
# Start mongod
echo "Start mongod "
docker exec DockerizedSample service mongod start
echo "IP in Docker Host"
echo "$HOST_IN_CONTAINER_IP"
echo "Local IP"
ipconfig getifaddr en0
# Open localhost in a browser on macOS
if [[ "$OSTYPE" =~ ^darwin ]];
then open http://localhost:8001/
fi;
如何重现问题
- 下载Php-Apache-Mongo/zip/master
- 进入PHPStorm文件夹并运行shell脚本
./run.sh
构建映像(可能需要几分钟)并运行容器后,它应该会在 http://localhost:8001/ 上打开浏览器
我目前的测试环境
- PhpStorm 2016.2.1
- 构建 #PS-162.1889.1,构建于 2016 年 8 月 23 日
- 您拥有此版本的永久后备许可证
- JRE:1.8.0_76-release-b216 x86_64
- JVM:JetBrains s.r.o 的 OpenJDK 64 位服务器虚拟机
- macOS Sierra 10.12 (16A323)
- Docker for mac 安装自官方docker for mac 版本 1.12.1 (build: 12133) 2d5b4d9c3daa089e3869e6355a47dd96dbf39856
【问题讨论】: