I'm setting up a Docker development environment for my team. In this environment we want to integrate Xdebug with Docker to allow for debugging. It seems the easiest way to do this is to connect Sublime Text to the Docker instance and then install Xdebug ontop on Sublime Text. I found the following guide for integrating Sublime Text with Docker (http://domeide.github.io/) and this guide for integrating Xdebug with Sublime Text (https://www.sitepoint.com/debugging-xdebug-sublime-text-3/). What I am wondering is if anyone has any experience setting up similar environments? Is there an easier way to do this? Does this seem like the correct way to debug PHP code inside Docker?
我正在为我的团队建立一个Docker开发环境。在这种环境中,我们希望将Xdebug与Docker集成以允许调试。看来最简单的方法是将Sublime Text连接到Docker实例,然后在Sublime Text上安装Xdebug ontop。我找到了以下指南,用于将Sublime Text与Docker集成(http://domeide.github.io/)和本指南,用于将Xdebug与Sublime Text集成(https://www.sitepoint.com/debugging-xdebug-sublime-text -3 /)。我想知道的是,是否有人有建立类似环境的经验?有更简单的方法吗?这看起来像是在Docker中调试PHP代码的正确方法吗?
1 个解决方案
#1
1
This solution may also work for Sublime Text - For Visual Studio Code, I have just recently got this working. I found these remote_host and other Xdebug settings work for me on both Windows 10 Pro and OS X using the latest versions of Docker Community Edition.
这个解决方案也适用于Sublime Text - 对于Visual Studio Code,我最近才开始使用它。我发现这些remote_host和其他Xdebug设置在Windows 10 Pro和OS X上都可以使用最新版本的Docker Community Edition。
In the Xdebug extension configuration, I set these along with the Xdebug extension installation in the Dockerfile of the image package from docker hub that contains php. There is a link to a post at the bottom of this answer on how this was done in the Dockerfile and how the image was built and then added to the docker-compose file.
在Xdebug扩展配置中,我将这些与Xdebug扩展安装一起设置在包含php的docker hub的映像包的Dockerfile中。这个答案底部的帖子有一个链接,关于如何在Dockerfile中完成此操作以及如何构建映像,然后将其添加到docker-compose文件中。
- The
xdebug.remote_connect_back
setting needs to be off:xdebug.remote_connect_back=0
- xdebug.remote_connect_back设置需要关闭:xdebug.remote_connect_back = 0
- Autostart
xdebug.remote_autostart=1
it just works. - 自动启动xdebug.remote_autostart = 1它只是工作。
- xdebug.remote_host=127.0.0.1 needs to be changed depending on Windows or OS X as follows:
- xdebug.remote_host = 127.0.0.1需要根据Windows或OS X进行更改,如下所示:
Windows 10 Professional running Docker Version 17.03.0-ce-win1, open a command prompt and enter ipconfig. The address is listed under DockerNAT. For example:
Windows 10 Professional运行Docker版本17.03.0-ce-win1,打开命令提示符并输入ipconfig。该地址列在DockerNAT下。例如:
ipconfig
Ethernet adapter vEthernet (DockerNAT):
IPv4 Address. . . . . . . . . . . : 10.0.75.1
OS X El Capitan running Docker Version 17.03.0-ce-mac2, create an alias of IP 10.254.254.254 to your existing subnet mask.
OS X El Capitan运行Docker版本17.03.0-ce-mac2,为您现有的子网掩码创建IP 10.254.254.254的别名。
sudo ifconfig en0 alias 10.254.254.254 255.255.255.0
Then use the IP for the xdebug.remote_host
setting for your host as follows based on the examples above:
然后根据上面的示例,使用IP为主机的xdebug.remote_host设置:
- Windows
10.0.75.1
- Windows 10.0.75.1
- OS X:
10.254.254.254
- OS X:10.254.254.254
Note, if you run into a conflict in OS X, you can remove the alias like so.
注意,如果在OS X中遇到冲突,可以删除这样的别名。
sudo ifconfig en0 -alias 10.254.254.254
I use Visual Studio Code with the vscode-php-debug PHP Debug Adapter to Listen for Xdebug and step through my code. Note the following needs to be included in the project launch.json
file in order for VS Code to map the remote server files to the local machine. This is from my project and its typical volume locations, your serverSourceRoot looks to be the same.
我使用Visual Studio Code与vscode-php-debug PHP调试适配器来监听Xdebug并逐步执行我的代码。请注意,项目launch.json文件中需要包含以下内容,以便VS Code将远程服务器文件映射到本地计算机。这是来自我的项目及其典型的卷位置,您的serverSourceRoot看起来是相同的。
"serverSourceRoot": "/var/www/html",
"localSourceRoot": "${workspaceRoot}"
The entire setup for docker-compose, nginx-proxy including how to build the image with Xdebug and more at Docker WordPress Dev Environment - Remote Debugging with Xdebug and VS Code
docker-compose,nginx-proxy的整个设置,包括如何在Docker WordPress Dev环境中使用Xdebug等构建映像 - 使用Xdebug和VS Code进行远程调试
#1
1
This solution may also work for Sublime Text - For Visual Studio Code, I have just recently got this working. I found these remote_host and other Xdebug settings work for me on both Windows 10 Pro and OS X using the latest versions of Docker Community Edition.
这个解决方案也适用于Sublime Text - 对于Visual Studio Code,我最近才开始使用它。我发现这些remote_host和其他Xdebug设置在Windows 10 Pro和OS X上都可以使用最新版本的Docker Community Edition。
In the Xdebug extension configuration, I set these along with the Xdebug extension installation in the Dockerfile of the image package from docker hub that contains php. There is a link to a post at the bottom of this answer on how this was done in the Dockerfile and how the image was built and then added to the docker-compose file.
在Xdebug扩展配置中,我将这些与Xdebug扩展安装一起设置在包含php的docker hub的映像包的Dockerfile中。这个答案底部的帖子有一个链接,关于如何在Dockerfile中完成此操作以及如何构建映像,然后将其添加到docker-compose文件中。
- The
xdebug.remote_connect_back
setting needs to be off:xdebug.remote_connect_back=0
- xdebug.remote_connect_back设置需要关闭:xdebug.remote_connect_back = 0
- Autostart
xdebug.remote_autostart=1
it just works. - 自动启动xdebug.remote_autostart = 1它只是工作。
- xdebug.remote_host=127.0.0.1 needs to be changed depending on Windows or OS X as follows:
- xdebug.remote_host = 127.0.0.1需要根据Windows或OS X进行更改,如下所示:
Windows 10 Professional running Docker Version 17.03.0-ce-win1, open a command prompt and enter ipconfig. The address is listed under DockerNAT. For example:
Windows 10 Professional运行Docker版本17.03.0-ce-win1,打开命令提示符并输入ipconfig。该地址列在DockerNAT下。例如:
ipconfig
Ethernet adapter vEthernet (DockerNAT):
IPv4 Address. . . . . . . . . . . : 10.0.75.1
OS X El Capitan running Docker Version 17.03.0-ce-mac2, create an alias of IP 10.254.254.254 to your existing subnet mask.
OS X El Capitan运行Docker版本17.03.0-ce-mac2,为您现有的子网掩码创建IP 10.254.254.254的别名。
sudo ifconfig en0 alias 10.254.254.254 255.255.255.0
Then use the IP for the xdebug.remote_host
setting for your host as follows based on the examples above:
然后根据上面的示例,使用IP为主机的xdebug.remote_host设置:
- Windows
10.0.75.1
- Windows 10.0.75.1
- OS X:
10.254.254.254
- OS X:10.254.254.254
Note, if you run into a conflict in OS X, you can remove the alias like so.
注意,如果在OS X中遇到冲突,可以删除这样的别名。
sudo ifconfig en0 -alias 10.254.254.254
I use Visual Studio Code with the vscode-php-debug PHP Debug Adapter to Listen for Xdebug and step through my code. Note the following needs to be included in the project launch.json
file in order for VS Code to map the remote server files to the local machine. This is from my project and its typical volume locations, your serverSourceRoot looks to be the same.
我使用Visual Studio Code与vscode-php-debug PHP调试适配器来监听Xdebug并逐步执行我的代码。请注意,项目launch.json文件中需要包含以下内容,以便VS Code将远程服务器文件映射到本地计算机。这是来自我的项目及其典型的卷位置,您的serverSourceRoot看起来是相同的。
"serverSourceRoot": "/var/www/html",
"localSourceRoot": "${workspaceRoot}"
The entire setup for docker-compose, nginx-proxy including how to build the image with Xdebug and more at Docker WordPress Dev Environment - Remote Debugging with Xdebug and VS Code
docker-compose,nginx-proxy的整个设置,包括如何在Docker WordPress Dev环境中使用Xdebug等构建映像 - 使用Xdebug和VS Code进行远程调试