---
title: "Discussion on \"Graceful Shutdown and Health Checks for Node.js in Docker\" | Hashnode"
description: "Discussion on \"Graceful Shutdown and Health Checks for Node.js in Docker\". Catch SIGTERM, drain requests, close dependencies and add liveness and readiness checks so Node.js deploys in Docker never drop a request."
url: "https://hashnode.com/posts/graceful-shutdown-and-health-checks-for-node-js-in-docker-yhflp/6ae71d664bca7f0cfc395190"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Graceful Shutdown and Health Checks for Node.js in Docker](https://blog.zyvop.com/graceful-shutdown-and-health-checks-for-node-js-in-docker-yhflp?utm_source=hashnode&utm_medium=feed)

Catch SIGTERM, drain requests, close dependencies and add liveness and readiness checks so Node.js deploys in Docker never drop a request.

Nov 1 · 10 min read · blog.zyvop.com  
Read the article

-   [#devops](https://hashnode.com/tag/devops)
-   [#docker](https://hashnode.com/tag/docker)
-   [#healthcheck](https://hashnode.com/tag/healthcheck)
-   [#kubernetes](https://hashnode.com/tag/kubernetes)
-   [#nodejs](https://hashnode.com/tag/nodejs)

## Written by

[ZyVOP](https://hashnode.com/@zyvop)

@zyvop · Delhi, India

  
[View profile](https://hashnode.com/@zyvop)

The Developer Publishing Hub

One platform to write, cross-post to Dev.to, Medium, WordPress, Hashnode, and Bluesky, and protect your SEO with canonical links. Zero paywalls and full content ownership.

## Responses 3

Markdown supported · ⌘↵ to post

[Node Edge Ops](https://hashnode.com/@nodeedgeops)

[Nov 5](https://hashnode.com/posts/graceful-shutdown-and-health-checks-for-node-js-in-docker-yhflp/6ae71d664bca7f0cfc395190/comment/6aec4659b30513f7951cefcb)

On SIGTERM, flip readiness to fail first so the load balancer drains, keep liveness green while in-flight Express/Nest requests finish, then close the server and exit before the stop timeout. Mixing DB checks into the liveness probe is what turns a short dependency blip into a restart storm — keep liveness process-only and put dependency depth on readiness (or a separate monitor path) that never drives restarts.

Ops prove-out: docker stop (or an orchestrator rolling replace) a single replica under light traffic, watch readiness go 503 before connections drop, confirm no 5xx spike on the balancer, and measure that the process exits inside the stop grace window. If requests die immediately or the container is killed hard, readiness was not failing early enough or the shutdown handler never closed the listener.

[ZyVOP](https://hashnode.com/@zyvop)

[Nov 6](https://hashnode.com/posts/graceful-shutdown-and-health-checks-for-node-js-in-docker-yhflp/6ae71d664bca7f0cfc395190/comment/6aec4659b30513f7951cefcb#reply-6aed5df009556b5dce1121ac)

Exactly. Readiness and liveness serve different purposes, and mixing them is asking for trouble. Graceful shutdown is only complete when in-flight requests get time to finish before the process exits.

[Node Edge Ops](https://hashnode.com/@nodeedgeops)

[Nov 9](https://hashnode.com/posts/graceful-shutdown-and-health-checks-for-node-js-in-docker-yhflp/6ae71d664bca7f0cfc395190/comment/6aec4659b30513f7951cefcb#reply-6af204e0b86bec978a060848)

Yes — the other half that usually bites is the stop grace versus the balancer's drain window. If the container stopTimeout is shorter than how long the load balancer still sends work after readiness goes 503, those last in-flight requests still get cut. I fail readiness first, give the balancer a moment to drain, then close the listener, and keep the stop timeout a bit above the longest request the app actually allows.
