# Stage 1

FROM node:14.15.4 as node

WORKDIR /mydir

COPY . .

RUN npm install

RUN npm run build --prod

# Stage 2

FROM nginx:alpine

COPY --from=node mydir/dist/uiapp /usr/share/nginx/html

This Dockerfile is a multi-stage build that is used to build and deploy a Node.js application with a NGINX web server in a container.

This file has 2 stages

:

  1. This stage uses a Node.js base image (starts with a Node.js 14.15.4 base image) to set up the build environment for the application.

Sets the working directory to “/mydir”.

It copies the application code into the container (copies the current directory into the container) and installs dependencies using npm.

Then runs the build command to create a production build of the application in the /mydir/dist directory.

  1. This stage uses an NGINX base image to create a production image of the application.

It copies the production build created in Stage 1 from the /mydir/dist directory to the NGINX web server’s default directory for serving static content, /usr/share/nginx/html.

The resulting Docker image will contain the NGINX web server and the built production files of the Node.js application. When we run the container, NGINX will serve the static files of the application.