Nodejs docker best practices
Skill EastSun5566/skills/skills/nodejs-docker-best-practices
Create, review, and improve Dockerfiles and container configurations for production Node.js applications. Use for Node.js image selection, dependency installation, multi-stage builds, build caching, non-root execution, signal handling, native modules, image size, runtime security, .dockerignore files, Compose services, or containerized test workflows.From its SKILL.md
npx -y skills add EastSun5566/skills --skill nodejs-docker-best-practicesAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
4.4 KB, 779 tokens by cl100k_base, as published. Nobody here has run it
Node.js Docker Best Practices
Inspect the application before changing its container setup. Apply only the guidance that fits its runtime, package manager, framework, native dependencies, and deployment platform.
Read references/best-practices.md before creating or substantially changing a production Dockerfile. Use its review checklist for smaller reviews.
Workflow
- Inspect the relevant files, including
Dockerfile*,.dockerignore, Compose files, package manifests, lockfiles, build configuration, and deployment manifests. - Determine:
- the supported Node.js version and image family;
- the package manager and exact lockfile;
- build, test, and runtime commands;
- generated artifacts and production dependency needs;
- native modules or operating-system packages;
- runtime ports, writable paths, signals, and shutdown behavior.
- Preserve the project's package manager, lockfile, runtime contract, and deployment assumptions unless the user asks to change them.
- Design the stages and layer order before editing. Keep build tooling out of the runtime image when practical.
- Implement the smallest coherent change. Update
.dockerignore, Compose, CI, or deployment files only when the Dockerfile change requires it. - Verify the touched path with the strongest checks available: parse or lint the Dockerfile, build the relevant target, run its tests, start the container, and exercise shutdown or health behavior as appropriate.
Decision Rules
- Prefer a supported, explicit Node.js image tag. Choose Debian slim, Alpine, distroless, or hardened images according to compatibility and operational needs rather than image size alone.
- Use the repository's lockfile and deterministic install command. Fail instead of silently selecting a different package manager or generating a new lockfile.
- Separate dependency installation from source copying so dependency layers remain cacheable. Use BuildKit cache mounts when the build environment supports them.
- Use multi-stage builds when compilation, testing, or native build tools are unnecessary at runtime. Keep build and runtime operating systems and libc compatible when copying native modules.
- Run as a non-root user. Ensure copied files and required writable directories have the correct ownership before switching users.
- Launch the application with exec-form
CMD. Prefer invokingnodedirectly in production unless a required launcher correctly forwards signals. - Decide explicitly how PID 1 responsibilities are handled. Use the platform's init option or a small init process when child reaping or signal forwarding requires it, and make the application handle graceful shutdown.
- Keep credentials out of Dockerfile
ARG,ENV, copied files, and image history. Use runtime secrets or BuildKit secret mounts. - Keep the build context narrow with
.dockerignore; never exclude files required by lockfile-based installation or the build. - Treat
NODE_ENV=production,EXPOSE, health checks, resource limits, and read-only filesystems as runtime-contract decisions, not boilerplate to add blindly. - Avoid global package installation when a project-local dependency or package-manager runner is sufficient.
Review Output
When reviewing an existing setup:
- Report concrete findings in severity order with file and line references.
- Explain the build, runtime, security, or operability consequence.
- Recommend the smallest safe fix and note meaningful tradeoffs.
- Distinguish verified defects from optional hardening or image-size improvements.
- Do not rewrite a working Dockerfile solely to match a preferred template.
When creating or modifying files, summarize the resulting build/runtime shape and the verification performed.
Freshness
The bundled reference is a synthesis, not a frozen substitute for upstream documentation. If the request asks for the latest image tags, Node.js support status, Dockerfile syntax, Docker features, or security recommendations, verify those details against the official sources linked in the reference before answering.
What ships with it: 1 file
13.1 KB alongside SKILL.md
references/
- best-practices.md13.1 KB
Gives 1 of the 12 instructions most containers cloud skills give in 779 tokens
Counted across 607 of the 657 authors here whose files we hold, read 2026-08-07
- Run containers as a non-root userhere, and in 66 of 607, across 46 files
- Use multi-stage buildsin 53 of 607, across 44 files
- Use Promise.all for independent operationsin 47 of 607, across 13 files
- Import directly instead of barrel filesin 46 of 607, across 12 files
- Use ternary instead of AND for conditionalsin 45 of 607, across 12 files
- Use Set or Map for O(1) lookupsin 42 of 607, across 10 files
- Create a .dockerignore filein 41 of 607, across 31 files
- Read individual rule files for detailsin 39 of 607, across 9 files
- Copy dependency files before source codein 36 of 607, across 23 files
- Authenticate server actions like API routesin 35 of 607, across 7 files
- Use next/dynamic for heavy componentsin 34 of 607, across 9 files
- Use React.cache for per-request deduplicationin 34 of 607, across 10 files
Said here and by no other author read
- inspect relevant files before changing setup
- preserve the project package manager and lockfile
- fail instead of changing package managers
- launch with exec-form CMD
- keep credentials out of image history
- verify changes using the strongest checks available
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.