THN Interview Prep

Docker images & containers for Node.js

Core details

Image = immutable filesystem + metadata; container = running instance from image + writable layer + cgroups limits.

Practices for Node services

PracticeWhy
Multi-stage buildtiny final image; dev deps don’t ship
NODE_ENV=productionleaner installs, behavior flags
Non-root USERblast radius on escape
dumb-init / initPID 1 reaps zombies; signals reach Node
Read-only root where possiblereduce tamper surface
.dockerignorefaster builds; no node_modules copy from host

Signals: container stop sends SIGTERM—shutdown hooks close server gracefully before SIGKILL.

Healthcheck: HTTP /health or TCP; distinct liveness vs readiness (Kubernetes split).

Understanding

Layer caching: order Dockerfile so dependency layers change less often than app code. Pin base images with digest for reproducibility.

Senior understanding

PitfallStory
Fat imagesslow pull → cold start on scale-out
Logging to file in containeruse stdout for collector
Secrets in imageuse runtime injection only

Diagram

Loading diagram…

See also

Last updated on

Spotted something unclear or wrong on this page?

On this page