-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dockerfile improvements #10326
Comments
@bmaupin, thanks for your suggestion. |
I think my original wording in the issue description was a bit misleading so I tried to update it. The short version is that As far as I understand, In addition, modifying the existing Dockerfile (I think this is it? and replacing I had to solve this with a multi-stage build in my example above, where the first stage uses |
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. |
Describe the bug
Since the loopback scaffolding automatically generates a
Dockerfile
, I've noticed a lot of developers in our organisation assume that this Dockerfile is ready out-of-the-box for production deployments.Is the generated
Dockerfile
meant for local developer use? In this case, I think it might be good to mention this somewhere (maybe in the Dockerfile itself) and that it needs some adjustments to be production ready.Alternatively, I would suggest these changes:
npm install
, which is great for local development, but I think it should benpm ci
for deployments.npm ci --only=production
would be even better, but that won't work without additional changes, because of my next point.docker build .
), the image size is 393MB because it includes all of the original TypeScript, the transpiled JavaScript, dependencies, and devDependencies. Changingnpm install
tonpm ci --only=production
won't work in a single-stage build because those devDependencies are needed to transpile the TypeScript. By using a multi-stage build, this allows only including the needed files, which reduces the image size to 277MB, and should have a positive impact on storage, deployment times, application startup times, etc.npm start
, which callsprestart
, which callsrebuild
, which callsbuild
(and so on). The build should be done when the container is built, so when the container is run, all it has to do is run the code.I'm not an expert, but here's a Dockerfile that uses a mutli-stage build to fix all of the above issues:
Logs
No response
Additional information
No response
Reproduction
npm install
tonpm ci --only=production
in DockerfileThe text was updated successfully, but these errors were encountered: