在mac OS上的停靠PHP中使用XDebug 问题
我无法从macOS上的停靠容器中使用Xdebug进行调试 我已经非常仔细地阅读了:,以及所有关于Stackoverflow和Github的建议解决方案。我还是被封锁了 在容器中 我可以连接到容器在mac OS上的停靠PHP中使用XDebug 问题,php,shell,docker,xdebug,Php,Shell,Docker,Xdebug,我无法从macOS上的停靠容器中使用Xdebug进行调试 我已经非常仔细地阅读了:,以及所有关于Stackoverflow和Github的建议解决方案。我还是被封锁了 在容器中 我可以连接到容器bash-c“clear&docker exec-it DockerizedSample sh” 它确认安装了XDebug # php -m -c [PHP Modules] Core ... xdebug ... [Zend Modules] Xdebug 它的配置似乎有效 # tail /usr/
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
docker文件
如何重现这个问题
/run.sh
- 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位服务器虚拟机
- 马科斯塞拉10.12(16A323)
- 从官方版本1.12.1安装的mac Docker(内部版本:12133)2D5B4D9C3DAA089E3869E63555A47DD96DBF39856
我终于找到了解决办法。它并不那么复杂。我使用“telnet”确定容器是否能够到达9000上的主机。事实并非如此。混乱来自远程主机IP。您必须使用您的本地主机IP
HOST_IP=$(ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}')
docker run -e PHP_IDE_CONFIG="serverName=DockerLocal"\
-e XDEBUG_CONFIG="idekey=PHPSTORM"\
-e XDEBUG_CONFIG="remote_host=$HOST_IP"\
-p 27017:27017 \
-p 8001:80\
-d --name DockerizedSample dockerizedsampleimage
检查
或者直接在上,自Docker 18.03发布以来,您的解决方案可以大大简化 运行docker容器可以使用
host.docker.internal
DNS名称。这些DNS条目保存docker主机的IP地址
所以不是
xdebug.remote\u host=172.17.0.1
你能行
xdebug.remote\u host=host.docker.internal
您还可以删除运行docker容器的运行脚本部分,该部分仅用于获取主机的IP地址。非常感谢Nikita。我已经找到了解决方案,它并不那么复杂。我将回答我自己的问题。这似乎是中所述的现在的
host.docker.internal
#!/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;
HOST_IP=$(ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}')
docker run -e PHP_IDE_CONFIG="serverName=DockerLocal"\
-e XDEBUG_CONFIG="idekey=PHPSTORM"\
-e XDEBUG_CONFIG="remote_host=$HOST_IP"\
-p 27017:27017 \
-p 8001:80\
-d --name DockerizedSample dockerizedsampleimage