Node.js & Docker tips

Random tips and tricks for Node.js app running in Docker (in no particular order).

  1. define your user just at the end of the file with USER node before running the app

  2. Don't use proxy commands like npm start or yarn start. They add complexity (additional process), and they block the exit signals (like SIGTERM) between Docker and Node.js as they’re being captured by npm/yarn. Run your file directly with node, e.g. CMD ["node", "index.js"]

  3. Limit how much memory your app can consume using flags --memory "300M" --memory-swap "1G"

  4. Multi-stage builds. You can use different images to build and run your app (usually you can have a slimmer docker image for running).

  5. Clean up the build artifacts with RUN npm ci --production && npm clean cache --force to save space.

  6. Lint your Dockerfile with https://github.com/hadolint/hadolint

#NodeJS #Docker #TipsAndTricks #Public

More posts by @yt →
Powered by Mind This.