<p>My requirement is to optimize and secure base image for nodeJS. I have tried building it on SCRATCH using multistage docker but the final container getting into crashed state.</p>
<p>Looking for a sample docker file working on SCRATCH base.</p>

<p>It's very much possible to build NodeJS applications on docker scratch image. Commands on the Scratch needs to be thoroughly verified by pointing to right path for node executable, if not it will result in crash as there will be no command line interface on scratch base.</p>
<p>Here is the dockerfile for sample NodeJS todo application and git reference.</p>
<pre><code>FROM siva094/node-scratch-static:1 as buildnode
#########################
#### Source code  ########
########################
FROM alpine/git as codecheckout
WORKDIR /app
RUN git clone https://github.com/siva094/nodejs-todo.git
######################
#### Code Build #####
####################
FROM node:10-alpine as sourcecode
WORKDIR /app
COPY  --from=codecheckout /app/nodejs-todo/ ./
RUN npm install --prod
###################
#### Target APP ###
##################
FROM scratch
COPY --from=buildnode /node/out/Release/node /node
COPY --from=sourcecode /app ./
ENV PATH &quot;$PATH:/node&quot;
EXPOSE 3000
ENTRYPOINT [&quot;/node&quot;, &quot;index.js&quot;]
</code></pre>
<p>Git Reference - <a href="https://github.com/siva094/nodejs-todo" rel="nofollow noreferrer">https://github.com/siva094/nodejs-todo</a></p>
<p>Docker References:</p>
<p>NodeJS fully static build and NodeJS todo app</p>
<pre><code> docker pull siva094/node-fullystatic
 docker pull siva094/nodejs-scratch-todo
</code></pre>
<p>Adding reference for building a static node.</p>
<p>source code URL - github.com/siva094/Dockers/blob/master/Dockerfile</p>
<pre><code>FROM node:latest as builder
RUN apk --no-cache add --virtual native-deps \
  g++ gcc libgcc libstdc++ linux-headers autoconf automake make nasm python git &amp;&amp; \
  npm install --quiet node-gyp -g
RUN npm install --quiet node-gyp -g
RUN git clone https://github.com/nodejs/node &amp;&amp; \
    cd node &amp;&amp; \
    ./configure --fully-static --enable-static &amp;&amp; \
    make

FROM scratch
COPY --from=builder /node/out/Release/node /node
</code></pre>
