Container build and runtime
A container image packages the application and runtime; a container is a running instance of that image. Node applications need a reviewed runtime, predictable dependencies and an explicit process lifecycle. Use a build stage for compilation or tests and a smaller runtime stage containing only required output and production dependencies. Pin a reviewed base digest and update it under a security policy. Use npm ci with a committed compatible lockfile when dependencies exist; lifecycle scripts need review. Use a nonroot identity, a direct exec-form command, a restricted build context and a writable temporary location only where needed. A digest identifies content, not whether that content is secure. Do not embed secrets in image layers, copy the entire private workspace, or treat a successful build as a runtime test. Sources: https://docs.docker.com/build/building/best-practices/.
Formal Syntax & Structure
Inspect a proposed runtime policy (conceptual contract; see example)Working Example
import assert from 'node:assert/strict';const config={uid:10001,argv:['node','main.mjs'],readOnlyRoot:true};assert.ok(config.uid>0);assert.deepEqual(config.argv,['node','main.mjs']);console.log('nonroot direct command');