<p>I am making a kubernetes cluster for my microservices application.
I am building the docker image and for some reason, it gets stuck @npm install step :</p>
<blockquote>
<p>GETS STUCK HERE :</p>
</blockquote>
<pre><code>$ docker build -t karanshreds/client .
Sending build context to Docker daemon  626.2kB
Step 1/7 : FROM node:alpine
 ---&gt; 3bf5a7d41d77
Step 2/7 : ENV CI=true
 ---&gt; Running in 3ffe706d12a3
Removing intermediate container 3ffe706d12a3
 ---&gt; bcd186e89d1b
Step 3/7 : WORKDIR /app
 ---&gt; Running in 4b68ea73ef58
emoving intermediate container 4b68ea73ef58
 ---&gt; 2427bc0ae6e8
Step 4/7 : COPY package.json ./
 ---&gt; 2d26f309fb4d
Step 5/7 : RUN npm install
 ---&gt; Running in ce5043208676
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated @types/testing-library__dom@7.5.0: This is a stub types definition. testing-library__dom provides its own type definitions, so you do not need this installed.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
npm WARN deprecated core-js@2.6.11: core-js@&lt;3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.

</code></pre>
<blockquote>
<p>Dockerfile</p>
</blockquote>
<pre><code>FROM node:alpine
ENV CI=true
WORKDIR /app
COPY package.json ./
RUN npm install
COPY ./ ./ 
CMD [&quot;npm&quot;, &quot;start&quot;]

</code></pre>
<p>It works when I use <strong>node instead of node:alpine</strong>. <strong>But it creates an image of size 1GB+</strong>. Which I obviously do not want.</p>
<blockquote>
<p>#NOTE: Just in case if you're wondering what my package.json files has :</p>
</blockquote>
<pre><code>{
  &quot;name&quot;: &quot;client&quot;,
  &quot;version&quot;: &quot;0.1.0&quot;,
  &quot;private&quot;: true,
  &quot;dependencies&quot;: {
    &quot;@testing-library/jest-dom&quot;: &quot;^4.2.4&quot;,
    &quot;@testing-library/react&quot;: &quot;^9.5.0&quot;,
    &quot;@testing-library/user-event&quot;: &quot;^7.2.1&quot;,
    &quot;axios&quot;: &quot;^0.19.2&quot;,
    &quot;react&quot;: &quot;^16.13.1&quot;,
    &quot;react-dom&quot;: &quot;^16.13.1&quot;,
    &quot;react-scripts&quot;: &quot;3.4.1&quot;
  },
  &quot;scripts&quot;: {
    &quot;start&quot;: &quot;react-scripts start&quot;,
    &quot;build&quot;: &quot;react-scripts build&quot;,
    &quot;test&quot;: &quot;react-scripts test&quot;,
    &quot;eject&quot;: &quot;react-scripts eject&quot;
  },
  &quot;eslintConfig&quot;: {
    &quot;extends&quot;: &quot;react-app&quot;
  },
  &quot;browserslist&quot;: {
    &quot;production&quot;: [
      &quot;&gt;0.2%&quot;,
      &quot;not dead&quot;,
      &quot;not op_mini all&quot;
    ],
    &quot;development&quot;: [
      &quot;last 1 chrome version&quot;,
      &quot;last 1 firefox version&quot;,
      &quot;last 1 safari version&quot;
    ]
  }
}

</code></pre>

<p>I am not sure what the issue is with running the <code>npm install</code> command, the logs seem to provide no reason to believe that there is actually something wrong in them, all i see are some warning messages about some packages being deprecated but not in fact errors. Either way, you said that it did work when you used <code>node</code> instead of <code>node:alpine</code>, which can help us.</p>
<p>Usually what you would want is: to build the app and have it running in separate docker layers. You can use multi-stage docker build for that purpose. This way you will have a separate environment in which you can build your app (<code>node</code> as required) and separate for running it, let's say minimal nginx. Below you can see an example of a single <code>Dockerfile</code> supporting the notion</p>
<pre><code># build environment
FROM node as build
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
RUN npm install
COPY . ./
RUN npm run build

# production environment
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD [&quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot;]
</code></pre>
