Skip to content

Feedback before writing: Install npm packages for production (Docker build) #699

@goldbergyoni

Description

@goldbergyoni

Context: This is used to share my TOC of a new best practice so I can solicit feedback and ideas before start writing. From my experience, this makes the writing experience much easier and shorter. And fun.

Title: Install npm packages for production

  • TL&DR: When finalizing the docker image for production, a safe package installation should be executed (npm ci) and with only production dependencies
  • Otherwise: Dev packages weakness can be used for attacks. Image size is increased for no reason.
  • Simple explanation - On the need to ship a safe image to production, what can go wrong with dev dependency (some of the last attacks were on dev packages), what can go wrong when not using 'npm ci', why image size is increased. What if we do need the dev dependency in Docker, how to remove them finally
  • Advanced tip - As a bonus, we can also clean the npm cache and reduce the image size even more
  • Code example: RUN npm ci --production && npm cache clean --force

Thoughts? improvement? Help me to make it better

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions