docker容器调试_如何在Docker容器中调试Node.js

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:

  1. Create a docker-compose.yaml for 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.yaml

Docker will combine docker-compose and debug-compose Overriding the first files configuration with the second. Check docker documentation for details.

Docker将结合docker-composedebug-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的最后一行DockerfileCMD ["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容器调试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值