简体   繁体   English

docker node app总是使用nodemon在文件更改时崩溃

[英]docker node app always crashes on file change using nodemon

I am using the latest version of docker and the latest node image. 我正在使用最新版本的docker和最新的节点映像。 I have a gulpfile that starts a nodemon process. 我有一个启动nodemon进程的gulpfile。 I am using the --inspect flag to indicate I want to use the experimental chrome dev tool debugger. 我使用--inspect标志来表示我想使用实验性的chrome dev工具调试器。 But when I make a file change it nodemon picks it up and restarts the process but crashes. 但是当我更改文件时,nodemon会将其选中并重新启动进程但崩溃。

Here is my gulp task: 这是我的gulp任务:

gulp.task('start:dev', done => {
  let started = false;
  nodemon({
    script: path.join(__dirname, 'index.js'),
    ext: 'js json',
    nodeArgs: ['--inspect=0.0.0.0:9229'],
    watch: path.join(__dirname, 'express'),
    legacyWatch: true
  })
  .on('start', () => {
    // to avoid nodemon being started multiple times
    if (!started) {
      setTimeout(() => done(), 100);
      started = true;
    }
  });
});

And here is the error: 这是错误:

Starting inspector on 0.0.0.0:9229 failed: address already in use

If I change the --inspect flag to be --debug it works like a charm. 如果我将--inspect标志更改为--debug它就像一个魅力。

I am guessing is that the restart process is too fast for the --inspect to release its port. 我猜测重启过程对于--inspect释放其端口来说太快了。 If I make another file change it does work and restarts normally. 如果我进行另一个文件更改它会工作并正常重新启动。 Probably since it had time to release the port. 可能因为它有时间释放端口。

I have tried using a delay on nodemon but I'd rather not. 我试过在nodemon上使用延迟,但我宁愿不这样做。 I would like quick restarts. 我想快速重启。 And I have tried using to events, like, restart and exit, to wait for a few seconds and then restart the whole gulp task. 我已经尝试使用事件,比如,重启和退出,等待几秒钟,然后重新启动整个gulp任务。 But that was temperamental and again I want quick restarts without having to hack together something. 但这是不稳定的,我想再次快速重启,而不必破解一些东西。

Right now I just switched back to --debug but that is deprecated in the latest V8. 现在我刚刚切换回--debug但在最新的V8中已弃用。 They are recommending to use --inspect . 他们建议使用--inspect

Maybe the only way is to lock down my version of node? 也许唯一的办法是锁定我的节点版本?

Any suggestions? 有什么建议?

Just kill inspector and start inspector again here is our team's solution in our package.json . 只需杀死检查员并再次启动检查员,这是我们团队在package.json的解决方案。 You had better kill inspector process and then restart inspector 您最好终止检查程序进程,然后重新启动检查程序

"inspect": "kill-port --port 9229 && node --inspect=0.0.0.0:9229 build/startup.js", "start_watch_inspect": `nodemon --delay 80ms --watch build/ build/startup.js --exec 'npm run inspect'`

Seems like this is related to: https://github.com/remy/nodemon/issues/1492 这似乎与以下内容有关: https//github.com/remy/nodemon/issues/1492

My workaround is to run this before each restart: (in a makefile, gulp file etc...) 我的解决方法是在每次重启之前运行它:(在makefile,gulp文件等......)

lsof -i -n | grep 9229 | awk '{print $2}' | xargs kill

** If put inside a Makefile remember to replace $ with $$ ** **如果放入Makefile内,请记得用$$替换$ **

There is an open issue addressing this problem. 这里是一个开放的问题,解决这一问题。

The easiest workaround I found so far was using "signal": "SIGINT" in my nodemon.json thanks to this comment . 到目前为止我发现的最简单的解决方法是在我的nodemon.json中使用"signal": "SIGINT" ,这要归功于这个评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM