title: How to build a docker image from a nodejs project in a monorepo with yarn workspaces
body: <p>We are currently looking into CI/CD with our team for our website. We recently also adapted to a monorepo structure as this keeps our dependencies and overview a lot easier. Currently testing etc is ready for the CI but I'm now onto the deployment. I would like to create docker images of the needed packages.</p>
  
  <p>Things I considered:    </p>
  
  <p>1) Pull the full monorepo into the docker project but running a yarn install in our project results in a total project size of about 700MB and this mainly due to our react native app which shouldn't even have a docker image. Also this should result in a long image pull time every time we have to deploy a new release</p>
  
  <p>2) Bundle my projects in some kind of way. With our frontend we have working setup so that should be ok. But I just tried to add webpack to our 
  express api and ended up with an error inside my bundle due to this issue: <a href="https://github.com/mapbox/node-pre-gyp/issues/308" rel="noreferrer">https://github.com/mapbox/node-pre-gyp/issues/308</a></p>
  
  <p>3) I tried running yarn install only inside the needed project but this will still install my node_modules for all my projects.</p>
  
  <p>4) Run the npm package: <a href="https://github.com/zeit/pkg" rel="noreferrer">pkg</a>. This results in a single file ready to run on a certain system with a certain node version. This DOES work but I'm not sure how well this will handle errors and crashes.</p>
  
  <p>5) Another solution could be copying the project out of the workspace and running a yarn install on it over there. The issue with this is that the use of yarn workspaces (implicitly linked dependencies) is as good as gone. I would have to add my other workspace dependencies explicitly. A possibility is referencing them from a certain commit hash, which I'm going to test right now. (EDIT: you can't reference a subdirectory as a yarn package it seems)</p>
  
  <p>6) ???</p>
  
  <p>I'd like to know if I'm missing an option to have only the needed node_modules for a certain project so I can keep my docker images small.</p>