My project uses nodemon inside Docker. It runs perfectly, but when I stop the process from my terminal with Ctrl+C, the container doesn't get turned off immediately. Instead, I have to wait for exactly 10 seconds before Docker finally kills it.
My guess is that nodemon fails to trap the SIGINT signal and doesn't act on it.
Docker container should immediately exit.
Docker container exits after a 10 second delay.
$ npm run dev
> dev
> docker compose up --build --no-log-prefix
[+] Building 2.5s (9/9) FINISHED docker:desktop-linux
=> [node internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 136B 0.0s
=> [node internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [node internal] load metadata for docker.io/library/node:18-bullseye-slim 0.0s
=> [node internal] load build context 0.0s
=> => transferring context: 206B 0.0s
=> [node 1/4] FROM docker.io/library/node:18-bullseye-slim 0.0s
=> CACHED [node 2/4] WORKDIR /app 0.0s
=> [node 3/4] COPY package.json . 0.0s
=> [node 4/4] RUN npm i 2.3s
=> [node] exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:f10b8543d5d6127ed57669be50b428a99bf75dd3babdc1179589c7d25582f4d1 0.0s
=> => naming to docker.io/library/test-node 0.0s
[+] Running 1/1
✔ Container test-node-1 Recreated 0.1s
Attaching to test-node-1
> start
> nodemon src/script.js --dump
[nodemon] 3.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,cjs,json
--------------
node: v18.19.0
nodemon: 3.0.2
command: /usr/local/bin/node /app/node_modules/.bin/nodemon src/script.js --dump
cwd: /app
OS: linux x64
--------------
{
run: false,
system: { cwd: '/app' },
required: false,
dirs: [ '/app' ],
timeout: 1000,
options: {
dump: true,
ignore: [
'**/.git/**',
'**/.nyc_output/**',
'**/.sass-cache/**',
'**/bower_components/**',
'**/coverage/**',
'**/node_modules/**',
re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*/
],
watch: [ '*.*', re: /.*\..*/ ],
monitor: [
'*.*',
'!**/.git/**',
'!**/.nyc_output/**',
'!**/.sass-cache/**',
'!**/bower_components/**',
'!**/coverage/**',
'!**/node_modules/**'
],
ignoreRoot: [
'**/.git/**',
'**/.nyc_output/**',
'**/.sass-cache/**',
'**/bower_components/**',
'**/coverage/**',
'**/node_modules/**'
],
restartable: 'rs',
colours: true,
execMap: { py: 'python', rb: 'ruby', ts: 'ts-node' },
stdin: true,
runOnChangeOnly: false,
verbose: false,
signal: 'SIGUSR2',
stdout: true,
watchOptions: {},
execOptions: {
script: 'src/script.js',
exec: 'node',
args: [],
scriptPosition: 0,
nodeArgs: undefined,
execArgs: [],
ext: 'js,mjs,cjs,json',
env: {}
}
},
load: [Function (anonymous)],
reset: [Function: reset],
lastStarted: 0,
loaded: [],
watchInterval: null,
signal: 'SIGUSR2',
command: {
raw: { executable: 'node', args: [ 'src/script.js' ] },
string: 'node src/script.js'
}
}
--------------
test-node-1 exited with code 0
As I posted on Stack Overflow:
My project uses nodemon inside Docker. It runs perfectly, but when I stop the process from my terminal with Ctrl+C, the container doesn't get turned off immediately. Instead, I have to wait for exactly 10 seconds before Docker finally kills it.
My guess is that nodemon fails to trap the SIGINT signal and doesn't act on it.
nodemon -v: 3.0.2nodemon src/script.jsExpected behaviour
Docker container should immediately exit.
Actual behaviour
Docker container exits after a 10 second delay.
Steps to reproduce
I've made a GitHub repo with the example. Reproduction steps are in the README.
If applicable, please append the
--dumpflag on your command and include the output here ensuring to remove any sensitive/personal details or tokens.