You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Node v5.x.x does not exit on Ctrl-C in Docker container #4182
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 use docker stop $CONTAINER_ID and it will stop the container.
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 process.exit()
Should this issue be closed @adam-beck@evanlucas@chrisdopuch ? It seems like broken behaviour, since node usually exits on SIGINT on Mac, why should it need to have explicit handlers registered when running inside a Ubuntu-14 Docker container? It means that Node code is not portable in this regard, which seems like an odd decision if it is really intended.
Reacted by Cameron Hudson, Michele Lacchia, switch-to-gitlab and Slava
@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.
This should be reopened.
Also I am pretty sure our closing behaviour is faulty in a number of places.
E.g. in C++ we should register the default handler with std::signal, since std::raise would cause implementation defined behaviour. Which though I cal rule out to be the cause of this.
Again for reference, this commit c61b0e9 was believed to cause this.
Another solution, which doesn't require any change in the code, is to add --pid=host to the docker run startup arguments.
That will allow you to kill the host, with <CTRL>+C
Activity
evanlucas commentedon Dec 8, 2015
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
process.exit()chrisdopuch commentedon Dec 9, 2015
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
Ctrl-cDocker version 1.8.2
docker-machine version 0.4.1
OSX Yosemite 10.10.5
adam-beck commentedon Dec 10, 2015
The above code worked. Thanks @evanlucas & @chrisdopuch.
samsalisbury commentedon Jan 13, 2016
Should this issue be closed @adam-beck @evanlucas @chrisdopuch ? It seems like broken behaviour, since node usually exits on
SIGINTon Mac, why should it need to have explicit handlers registered when running inside a Ubuntu-14 Docker container? It means that Node code is not portable in this regard, which seems like an odd decision if it is really intended.chrisdopuch commentedon Jan 13, 2016
I agree @samsalisbury, and I would also still like to see this issue resolved.
MylesBorins commentedon Jan 13, 2016
/cc @nodejs/ctc
samsalisbury commentedon Jan 14, 2016
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.
misterdjules commentedon Jan 14, 2016
@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)?
MylesBorins commentedon Jan 14, 2016
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
evanlucas commentedon Jan 14, 2016
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.
Handle signals properly so CTRL-C exits container
Explicitly handle SIGINT to terminate on Ctrl+C from docker
Handle SIGINT exit, add hostname and \n to resp
hellonode: Handle SIGINT, add hostname and \n to response (#15)
eljefedelrodeodeljefe commentedon May 20, 2017
This should be reopened.
Also I am pretty sure our closing behaviour is faulty in a number of places.
E.g. in C++ we should register the default handler with
std::signal, sincestd::raisewould cause implementation defined behaviour. Which though I cal rule out to be the cause of this.Again for reference, this commit c61b0e9 was believed to cause this.
bnoordhuis commentedon May 20, 2017
@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.
eljefedelrodeodeljefe commentedon May 20, 2017
Will do.
Add an explicit sigint handler to wiseService and viewer (#776)
lakruzz commentedon Jun 11, 2018
Another solution, which doesn't require any change in the code, is to add
--pid=hostto the docker run startup arguments.That will allow you to kill the host, with
<CTRL>+Cthelebster commentedon Jun 15, 2018
@lakruzz this worked for me. I have a running

gulp watchtask from the docker on macosx.Add termination processing
slavafomin commentedon Jan 5, 2022
This really helped me 4 years later, thanks :)
smijar commentedon May 9, 2022
Thanks, brilliant!!