Javascript 为什么预期的消息不是';打印到控制台输出?

Javascript 为什么预期的消息不是';打印到控制台输出?,javascript,node.js,docker,alpine,Javascript,Node.js,Docker,Alpine,我问了一个关于SIGTERM的问题,我得到了答案:Windows不能发出这个信号。但是对于Linux,我遇到了同样的问题(我编写了新的代码示例)。。。我在节点14.14.0-alpine3.10的基础上构建linux docker映像: 我的Dockerfile: FROM node:14.14.0-alpine3.10 WORKDIR /opt/app/ COPY . . RUN npm i CMD npm run start // Build the image and start its

我问了一个关于SIGTERM的问题,我得到了答案:Windows不能发出这个信号。但是对于Linux,我遇到了同样的问题(我编写了新的代码示例)。。。我在
节点14.14.0-alpine3.10
的基础上构建linux docker映像:

我的
Dockerfile

FROM node:14.14.0-alpine3.10
WORKDIR /opt/app/
COPY . .
RUN npm i
CMD npm run start
// Build the image and start its container:
// docker build -t my-app .
// docker run -it --rm --name my-app my-app

const appArgs = require("minimist")(process.argv.slice(2));
const readline = require("readline").createInterface({
    input: process.stdin,
    output: process.stdout,
});
const signalName = "SIGTERM";

process.on(signalName, () => {
    console.log(`${signalName} happened.`); // I don't see this message. Why?
});

console.log("application args: %o", appArgs);

let name = null;
let age = null;
readline.question("Name: ", answer => {
    name = answer;
    readline.question("Age: ", answer => {
        age = answer;
        readline.close();
        printHello();
    });
});

function printHello() {
    console.log(`Hello, ${name} (${age} age)`);
    process.kill(process.pid, signalName);
}
我的
.dockrignore
文件:

node_modules/
{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "start": "node src/index.js -abc --def --ghj 'Bob' -- 11 22 33"
  },
  "keywords": [],
  "author": "Andrey Bushman",
  "license": "ISC",
  "dependencies": {
    "minimist": "^1.2.5"
  }
}
我的
src/index.js文件

FROM node:14.14.0-alpine3.10
WORKDIR /opt/app/
COPY . .
RUN npm i
CMD npm run start
// Build the image and start its container:
// docker build -t my-app .
// docker run -it --rm --name my-app my-app

const appArgs = require("minimist")(process.argv.slice(2));
const readline = require("readline").createInterface({
    input: process.stdin,
    output: process.stdout,
});
const signalName = "SIGTERM";

process.on(signalName, () => {
    console.log(`${signalName} happened.`); // I don't see this message. Why?
});

console.log("application args: %o", appArgs);

let name = null;
let age = null;
readline.question("Name: ", answer => {
    name = answer;
    readline.question("Age: ", answer => {
        age = answer;
        readline.close();
        printHello();
    });
});

function printHello() {
    console.log(`Hello, ${name} (${age} age)`);
    process.kill(process.pid, signalName);
}
我的
package.json
文件:

node_modules/
{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "start": "node src/index.js -abc --def --ghj 'Bob' -- 11 22 33"
  },
  "keywords": [],
  "author": "Andrey Bushman",
  "license": "ISC",
  "dependencies": {
    "minimist": "^1.2.5"
  }
}
我构建了基于linux的映像,并在Windows上运行其容器:

docker build -t my-app .
docker run -it --rm --name my-app my-app
控制台输出:

PS C:\Users\bushm\source\repos\node_sandbox\app> docker run -it --rm --name my-app my-app

> app@1.0.0 start /opt/app
> node src/index.js -abc --def --ghj 'Bob' -- 11 22 33

application args: {
  _: [ '11', '22', '33', [length]: 3 ],
  a: true,
  b: true,
  c: true,
  def: true,
  ghj: 'Bob'
}
Name: Bob
Age: 30
Hello, Bob (30 age)
PS C:\Users\bushm\source\repos\node_sandbox\app>
我的程序是由Linux而不是Windows启动的。为什么此时控制台输出中没有出现“SIGTERM coursed.”字符串