-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node v5.x.x does not exit on Ctrl-C in Docker container #4182
Comments
There is another issue (somewhere in the archive repo) that goes into detail on why that is the intended behavior (I'm searching for it). But, to work around, you can add listeners for those signals and then call |
I was able to reproduce this problem using Node 5.2.0, and I also reproduced the correct behavior with Node 0.10.41. @evanlucas your workaround does work great, added the following to @adam-beck 's code and was able to end the process in Node 5.2.0 with
Docker version 1.8.2 |
The above code worked. Thanks @evanlucas & @chrisdopuch. |
Should this issue be closed @adam-beck @evanlucas @chrisdopuch ? It seems like broken behaviour, since node usually exits on |
I agree @samsalisbury, and I would also still like to see this issue resolved. |
/cc @nodejs/ctc |
Also note that this is broken at least as early as node 4.2.3, which is what I'm using now, and probably earlier. |
@evanlucas Were you looking for nodejs/node-v0.x-archive#9131, as indicated at the bottom of the issue's description (maybe edited after your comment was posted)? |
nodejs/node-v0.x-archive#9131 (comment) seems to do a really good job of describing what is happening, and why this appears to be an issue with docker not node. The issue tracking this on docker was closed as fixed, and it seems if process.on('sigint') is firing than perhaps docker is passing the SIGINT to pid 1 as expected. I think someone with a bit more docker understanding needs to take a peak @nodejs/docker |
Thanks @misterdjules for the link. I was thinking there was another issue, but I have been unable to find it. I agree with @thealphanerd that the description in the previous issue explains it pretty well. But, since @indutny signed off on the commit that changed this behavior, perhaps he can shed some light on this. |
Based on this issue: - nodejs/node#4182 This is the proposed explanation and fix: - nodejs/node-v0.x-archive#9131 (comment)
- Ctrl+C on a Docker container sends SIGINT, which is not handled properly by default (see nodejs/node#4182). Added a signal handler. - Adding trailing newline to response for curl-friendliness. - Added log message indicating server is starting. - Added hostname to indicate that the container. Signed-off-by: Ahmet Alp Balkan <[email protected]>
* Handle SIGINT exit, add hostname and \n to resp - Ctrl+C on a Docker container sends SIGINT, which is not handled properly by default (see nodejs/node#4182). Added a signal handler. - Adding trailing newline to response for curl-friendliness. - Added log message indicating server is starting. - Added hostname to indicate that the container. Signed-off-by: Ahmet Alp Balkan <[email protected]> * Address code review comments Signed-off-by: Ahmet Alp Balkan <[email protected]>
This should be reopened. E.g. in C++ we should register the default handler with Again for reference, this commit c61b0e9 was believed to cause this. |
@eljefedelrodeodeljefe Then please file a new issue. This one is about PID 1 being special when it comes to signals, it's not a node issue. |
Will do. |
node ignores sigint when running as pid 1 in a docker container. An explicit sigint handler is needed in order for ^C to work or for systemd to manage the process. E.g. when running the viewer like ... docker run --rm moloch /data/moloch/bin/node /data/moloch/viewer/viewer.js See nodejs/node#4182 for details.
Another solution, which doesn't require any change in the code, is to add That will allow you to kill the host, with |
@lakruzz this worked for me. I have a running |
This really helped me 4 years later, thanks :) |
Thanks, brilliant!! |
server.js
docker run --rm -it -v /home/foo/repos/test/server.js:/usr/test/server.js -w /usr/test node node server.js
You are unable to kill the server by using
Ctrl-C
anymore. I've tried testing this with an older version of node (0.10.41
) and it seems to be working properly. I am able to usedocker stop $CONTAINER_ID
and it will stop the container.May be something similar to this
The text was updated successfully, but these errors were encountered: