title: How do I make yarn cache modules when building containers?
body: <p>This is my <code>Dockerfile</code> for local development:</p>
  <pre><code>FROM node:12-alpine
  
  WORKDIR /usr/app
  
  ENV __DEV__ 1
  
  COPY package.json ./
  COPY yarn.lock ./
  RUN yarn --frozen-lockfile
  
  COPY tsconfig.json ./
  COPY nodemon.json ./
  
  RUN apk add --no-cache tini
  ENTRYPOINT [&quot;/sbin/tini&quot;, &quot;--&quot;]
  
  CMD [ &quot;yarn&quot;, &quot;dev&quot; ]
  
  </code></pre>
  <p>This is how I build it:</p>
  <pre><code>docker build --rm -f Dockerfile.dev --tag my-app .
  </code></pre>
  <p>This is how I run it:</p>
  <pre><code>docker run --rm -it --volume $(pwd)/src:/usr/app/src -p 3000:3000 my-app
  </code></pre>
  <p>I need to build it only when something outside the <code>src</code> folder changes. For instance, when I install node modules. How to I make <code>yarn</code> to cache modules somewhere, so it would not pull all modules on each build.</p>