foundation

Containers

Run isolated processes from images with explicit ports, environment, volumes, resource limits, and lifecycle controls.

A container is a running process created from an image with isolated filesystem, process namespace, network settings, and environment. Treat containers as disposable: durable state belongs in databases, queues, object storage, or explicit volumes.

					docker run --rm -p 3000:3000 \
  -e NODE_ENV=production \
  --memory=512m --cpus=1 \
  my-api:1.4.2
				

| Setting | Purpose | |---------|---------| | `-p host:container` | Publish ports deliberately | | `-e` / `--env-file` | Inject configuration | | `--memory` / `--cpus` | Cap resource usage | | `--rm` | Remove ephemeral instances after exit |

Node.js services should handle `SIGTERM`: stop accepting traffic, drain in-flight requests, then exit with a clear code.

On interviews: entrypoints, environment variables, port publishing, resource limits, signals, exit codes, and graceful shutdown.

Common pitfalls: writing important data into the writable container layer; running multiple unrelated processes in one container; ignoring OOM kills without limits.

The trade-off is convenience (everything in one container) versus clear lifecycle, health signals, and operability.

Checklist:

  • Keep containers disposable.
  • Handle `SIGTERM` and drain work.
  • Externalize durable state.
  • Set memory and CPU limits in orchestrated environments.