title: Docker build takes long time for nodejs application
body: <p>I am experiencing long build times for nodejs applications when building image with docker build command.</p>
  
  <p>There is one big hang that takes couple of minutes</p>
  
  <pre><code>08:03:15  Step 1/11 : FROM node:14.1.0-alpine AS build
  08:03:15   ---&gt; 0854fcfc1637
  08:03:15  Step 2/11 : COPY server/package*.json /nodejs/server/
  08:03:15   ---&gt; Using cache
  08:03:15   ---&gt; 4996283ff991
  08:03:15  Step 3/11 : WORKDIR /nodejs/server
  08:03:15   ---&gt; Using cache
  08:03:15   ---&gt; 93e5b63fa81d
  08:03:15  Step 4/11 : RUN npm ci
  08:03:15   ---&gt; Using cache
  08:03:15   ---&gt; 2c825e02ea01
  08:03:15  Step 5/11 : COPY server ./
  08:03:15   ---&gt; Using cache
  08:03:15   ---&gt; 69c024cde79f
  08:03:15  Step 6/11 : WORKDIR /nodejs
  08:03:15   ---&gt; Using cache
  08:03:15   ---&gt; 49d7f8bd9514
  08:03:15  Step 7/11 : COPY package*.json ./
  08:03:16   ---&gt; e82bee625c3e
  08:03:16  Step 8/11 : RUN npm ci
  08:03:16   ---&gt; Running in ecfd57702906
  ...
  08:03:49  added 1483 packages in 26.419s
  08:09:40  Removing intermediate container ecfd57702906
  ...
  08:09:40   ---&gt; 7c6b67d85b0b
  08:09:40  Step 9/11 : COPY *.json ./
  08:09:43   ---&gt; 0165efd1c97d
  08:09:43  Step 10/11 : COPY src ./src/
  08:09:51   ---&gt; 42e54cee6b91
  08:09:51  Step 11/11 : RUN npm run build:prod
  08:09:51   ---&gt; Running in af6f9b013d27
  </code></pre>
  
  <p>This does not happen when building Java images.</p>
  
  <p>My Dockerfile</p>
  
  <pre><code>FROM node:14.1.0-alpine AS build
  COPY server/package*.json /nodejs/server/
  WORKDIR /nodejs/server
  RUN npm ci
  COPY server ./
  
  WORKDIR /nodejs
  COPY package*.json ./
  RUN npm ci
  COPY *.json ./
  COPY src ./src/
  RUN npm run build:prod
  ...
  </code></pre>
  
  <p>I tried using buildkit but it has the same behaviour</p>
  
  <pre><code>08:37:20  #17 exporting to image
  08:37:20  #17 exporting layers
  08:50:12  #17 exporting layers 766.8s done
  </code></pre>
  
  <p>I also added node_modules to .dockerignore file but with no change.</p>
  
  <p>Docker version 19.03.6, build 369ce74a3c</p>
  
  <p>What could be the problem?</p>
  
  <p>What is happening between "added 1483 packages..." and "Removing intermediate container"?</p>