docker容器调试
It can be tricky to debug a NodeJS application if you haven’t worked with docker for long. Let me save you some time!
如果您没有长期使用docker,调试NodeJS应用程序可能会很棘手。 让我为您节省一些时间!
The dockerfile I am using:
我正在使用的dockerfile:
Create a
docker-compose.yamlfor main configuration:创建
docker-compose.yaml作为主要配置:
2. Create a debug-compose.yaml for debug configuration:
2.创建一个debug-compose.yaml进行调试配置:
3. Add this configuration to your vscode launch.json file:
3.将此配置添加到您的vscode launch.json文件中:
4. Run:
4.执行:
docker-compose -f docker-compose.yaml -f debug-compose.yamlDocker will combine docker-compose and debug-compose Overriding the first files configuration with the second. Check docker documentation for details.
Docker将结合docker-compose和debug-compose覆盖第一个文件配置和第二个文件。 查看Docker 文档以获取详细信息。
5. Go to your vscode debug panel (CTRL + SHIFT + D) select Docker: Attach to Node from the menu and click run, the debugger will break on first line. You can change line 12 of debug-compose.yaml from --inspect-brk to --inspect to turn off breaking right away.
5.转到您的vscode调试面板(CTRL + SHIFT + D) Docker: Attach to Node从菜单中选择Docker: Attach to Node并单击运行,调试器将在第一行中断。 您可以将debug-compose.yaml第12行从--inspect-brk更改为--inspect以立即关闭中断。
If you are not using docker-compose . You can achieve the same thing by changing the the last line of Dockerfile to CMD ["node", "--inspect=0.0.0.0", "server.js" ] and running:
如果您不使用docker-compose 。 您可以通过将Dockerfile的最后一行Dockerfile为CMD ["node", "--inspect=0.0.0.0", "server.js" ]并运行以下Dockerfile来实现相同的Dockerfile :
docker build . docker run -p 9229:9229
docker build . docker run -p 9229:9229
翻译自: https://medium.com/@eneskhartum/how-to-debug-nodejs-inside-a-docker-container-d720bc017585
docker容器调试