Coder Social home page Coder Social logo

Dockerfile improvements about loopback-next HOT 3 OPEN

bmaupin avatar bmaupin commented on June 15, 2024
Dockerfile improvements

from loopback-next.

Comments (3)

dhmlau avatar dhmlau commented on June 15, 2024

@bmaupin, thanks for your suggestion.
Would it work better to use npm install --production then?

from loopback-next.

bmaupin avatar bmaupin commented on June 15, 2024

@bmaupin, thanks for your suggestion. Would it work better to use npm install --production then?

I think my original wording in the issue description was a bit misleading so I tried to update it. The short version is that npm ci --only=production is ideal for the final built image but will only work with some additional changes to the Dockerfile.

As far as I understand, npm install should only be used for local development. When building the application for deployment (especially for production), npm ci should be used. It ensures that the dependencies are installed cleanly and will also result in reproducible builds; this isn't the case with npm install because it may update packages in package-lock.json unless package versions are explicitly pinned.

In addition, modifying the existing Dockerfile (I think this is it? and replacing npm install with npm install --production will break the build, because the devDependencies are required for the npm run build command to work.

I had to solve this with a multi-stage build in my example above, where the first stage uses npm ci to install all dependencies (including devDependencies) and run the build, then in the second stage, the built JavaScript files are copied and npm ci --only=production is run to exclude devDependencies from the final container image.

from loopback-next.

bmaupin avatar bmaupin commented on June 15, 2024

I was working with a Loopback 4 application today and I noticed another issue with the generated Dockerfile: it does a build every time the container image is run. This of course is slower, and it also presents more potential points of failure at runtime.

The Dockerfile I proposed already remediates this, but I added an extra note about this in the issue description.

from loopback-next.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.