DEV Community

Discussion on: Reducing Docker image size of a Nuxt SSR application

Collapse
 
artalus profile image
Artalus

How about experiment with something like

RUN yarn install && yarn build --standalone && rm -rf node_modules && yarn add "nuxt-start@${NUXT_VERSION}"
Enter fullscreen mode Exit fullscreen mode

This should further decrease image bloat because node_modules will be created and deleted as part of a single layer creation "function".

Collapse
 
fbjorn profile image
Denis

Thanks for a suggestion, sounds pretty interesting. Need to try it out.

I'm using self-hosted agents for CI, so they keep docker cache between the builds. This way I'm able to skip yarn install part cause it's available in cache. Anyway I'll try your suggestion on the same codebase for clarity and report back soon!

Collapse
 
fbjorn profile image
Denis

@artalus please check 🙂

Thread Thread
 
artalus profile image
Artalus

My initial concern was about "why even have node_modules in final docker image at all", and I actually was hoping for 100Mb decrease. But couple of minutes after posting the suggestion I actually realized that, well, nuxt-start is a Node application itself, and it will likely require a lot of dependencies to work - because that's just the reality of Node applications ¯\_(ツ)_/¯. So the only gain would be due to removal of a slice of node_modules content that is required by yarn build but not by nuxt-start. But small gain is still a gain 🙃