4 ms·
I suppose you could apply the same builder/scrstch separation as this Dockerfile and install using npm/yarn/etc and copy over the result It's certainly only pr
by philplckthun 8y ago
I suppose you could apply the same builder/scrstch separation as this Dockerfile and install using npm/yarn/etc and copy over the result
It's certainly only practical when every byte matters. At that point it might also make sense to prebundle the dependencies and copy that over.
It'd be interesting to see whether this becomes relevant if serverless-like constraints suddenly apply to a Docker cloud service
- orliesaurus 8y agowait, do you mean adding another layer for npm installing other deps?
- jopsen 8y agoNo, doing npm install in a different container and copying over the result. Docker has multi-stage build, which allows using a container to build and copying over in a different result container.. I suspect this could be relevant many place, keeping images small also hardens security.
- orliesaurus 8y agoOh, what are the advantages of doing that in a different container as opposed to a different layer? Trying to understand the pros/cons.. Isn't it faster to add extra layers, than extra containers?
- wolfgang42 8y agoDifferent layer means you have to carry around that layer in your final image. If you do a multi-stage build, you can copy over just the bits you need into the final image.
- vsviridov 8y agoLayers are add only. If you removea file, it still exists in the parent layer, propagating bloat
- heroic 8y agoThis is the builder pattern in docker. You do things in one "throw away" container, use results from this container and copy them into another. The final container gets only one layer now, instead of maybe 10s that your "throw away" container had.
- misterdata 8y agoThat's exactly what the README suggests to do under 'Usage'. First it says 'FROM node', which is the regular 'fat' image. In this image it then runs `npm install`. Further on there is another 'FROM' which starts from the minimal image and copies over all the JS code (including the node_modules directory which has been populated by npm) from the 'fat' image (this of course would fail for bindings that require libraries outside the node_modules directory, although it is relatively easy to add more COPY statements to also put these in the appropriate locations).