Skip to content

Graceful shutdown of Docker container not respected #2152

@yandodov

Description

@yandodov

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.

  • Versions: node@v20.9.0, darwin@22.6.0
  • nodemon -v: 3.0.2
  • Operating system/terminal environment (powershell, gitshell, etc): Docker on macOS Ventura 13.6.3 (22G436)
  • Using Docker? What image: node:18-bullseye-slim
  • Command you ran: nodemon src/script.js

Expected 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 --dump flag on your command and include the output here ensuring to remove any sensitive/personal details or tokens.

$ 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    not-staleTell stalebot to ignore this issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions