Multi-stage builds / decreasing size #104
Replies: 6 comments
-
Hey there, great ideas, thanks for offering to help. I started this as debian-only over a year ago because alpine was not as common. Now many have made it their default and I think a non-default dockerfile would be a great addition for comparison.
|
Beta Was this translation helpful? Give feedback.
-
Hey @BretFisher I would like to work on this and start with multi-stage dockerfile. |
Beta Was this translation helpful? Give feedback.
-
OK, see other PR's active as well. |
Beta Was this translation helpful? Give feedback.
-
Hey @BretFisher, I'd like to make a PR for multistage builds! Is there any specific way you'd like this done or anything you'd want included? I was thinking of adding a build stage that would build with babel or typescript (would add support for #39) and a production stage that would install only production dependencies and copy the built files. Along with a development stage that would rebuild on nodemon restart and have all dependencies for development and debugging etc. This would be using the target build option in compose file (one issue would be that the compose file version would need to be bumped to 3.4). What are your thoughts on this? |
Beta Was this translation helpful? Give feedback.
-
Sure, but also note I'm working on multi-stage myself, but it would be great to compare solutions. I haven't pushed a commit yet so feel free to try using multi-stage yourself and submitting a PR of what you find useful. |
Beta Was this translation helpful? Give feedback.
-
Since I have multiple multistage examples now listed in the README (which are in other repos), I'm going to move this to a discussion. |
Beta Was this translation helpful? Give feedback.
-
First of all, thank you (+contributers) so much for creating this example project. It really helped me get past cold feet and actually set up a first nice Docker project!
As this guide popped up as my starting point I imagine others starting here as well. For completeness, I think it's worth highlighting multi-stage builds and smaller parent images to decrease your image size.
It's worth noting that the production version of this Hello World app still includes all the devDependencies, unit-tests and files that are not strictly necessary. Of course, multi-stage builds make more sense in larger applications with client-side js.
Also, just using node:alpine as parent image help getting from 600mb+ to ±70mb, worth mentioning too.
If leaving those out was intentional that's fine, you point to a good further reading resource, if you agree I'm more than happy to create a PR with these comments/changes implemented.
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions