sjm*_*ett 6 ubuntu node.js sigterm docker
我希望能够在docker容器中运行node,然后才能运行docker stop <container>.这应该停止容器,SIGTERM而不是超时和做SIGKILL.不幸的是,我似乎错过了一些东西,我发现的信息似乎与其他部分相矛盾.
这是一个测试Dockerfile:
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y curl
RUN curl -sSL http://nodejs.org/dist/v0.11.14/node-v0.11.14-linux-x64.tar.gz | tar -xzf -
ADD test.js /
ENTRYPOINT ["/node-v0.11.14-linux-x64/bin/node", "/test.js"]
Run Code Online (Sandbox Code Playgroud)
这是test.jsDockerfile中引用的:
var http = require('http');
var server = http.createServer(function (req, res) {
console.log('exiting');
process.exit(0);
}).listen(3333, function (err) {
console.log('pid is ' + process.pid)
});
Run Code Online (Sandbox Code Playgroud)
我这样构建它:
$ docker build -t test .
Run Code Online (Sandbox Code Playgroud)
我像这样运行它:
$ docker run --name test -p 3333:3333 -d test
Run Code Online (Sandbox Code Playgroud)
然后我跑:
$ docker stop test
Run Code Online (Sandbox Code Playgroud)
因此SIGTERM显然不起作用,导致它在10秒后超时然后死亡.
我发现,如果我启动节点任务,sh -c那么我可以^C从interactive(-it)容器中删除它,但我仍然无法开始docker stop工作.这与我已经读过的评论相矛盾,说sh不会传递信号,但可能会同意我读过的其他评论说PID 1没有得到SIGTERM(因为它是通过启动sh,它将是PID 2).
最终目标是能够docker start -a ...在upstart作业中运行并能够停止服务并且它实际上退出容器.
小智 6
SIGINT我的方法是在 JavaScript 中捕获(中断信号)。
process.on('SIGINT', () => {
console.info("Interrupted");
process.exit(0);
})
Run Code Online (Sandbox Code Playgroud)
Ctrl当您按+时,这应该可以解决问题C。
| 归档时间: |
|
| 查看次数: |
1575 次 |
| 最近记录: |