Close

2020-08-31

Docker best practices with Node.js

Docker best practices with Node.js

Welcome to our comprehensive list of Docker best practices exemplified under Node.js.

Note that every bullet has a link to detailed information and code examples. The entire list can be found in our repository Node.js Best Practices. It covers the basics but goes all the way to strategic decisions like how much and where to limit the container’s memory, how to prevent secrets from sticking to the image, is a process manager needed as the top process, or whether Node can act as PID1.

  •  Use multi-stage builds for leaner and more secure Docker images
  • Bootstrap using the ‘node’ command; avoid npm start.
  • Let the Docker runtime handle replication and uptime
  • Use .dockerignore to prevent leaking secrets
  • Clean-up dependencies before production
  • Shutdown smartly and gracefully
  • Set memory limits using both Docker and v8
  • Plan for efficient caching
  • Use explicit image reference, avoid the latest tag.
  • Prefer smaller Docker base images
  • Clean-out build-time secrets, avoid secrets in args
  • Scan images for multi-layers of vulnerabilities
  • Clean NODE_MODULE cache
  • Generic Docker practices
  • Lint your Dockerfile

For the details and the full article, please visit the original article https://dev.to/nodepractices/docker-best-practices-with-node-js-4ln4

Collected, curated, and written by: Yoni Goldberg, Bruno Scheufler, Kevyn Bruyere, and Kyle Martin