Skip to content

Instantly share code, notes, and snippets.

@sandeep540
Last active June 14, 2019 19:35
Show Gist options
  • Save sandeep540/acd30fd20f168df481222e86eb0acefe to your computer and use it in GitHub Desktop.
Save sandeep540/acd30fd20f168df481222e86eb0acefe to your computer and use it in GitHub Desktop.
Dockerfile multistage node
# ---- Base Node ----
FROM node:11.10 AS base
# Create app directory
WORKDIR /app
# ---- Dependencies ----
FROM base AS dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
# install app dependencies including 'devDependencies'
RUN npm install
# ---- Copy Files/Build ----
FROM dependencies AS build
WORKDIR /app
COPY . .
# Build react/vue/angular bundle static files
# RUN npm run build
# --- Release with Alpine ----
FROM node:11.10.0-alpine AS release
# Create app directory
WORKDIR /app
# optional
# RUN npm -g install serve
COPY --from=dependencies /app/package.json ./
# Install app dependencies
RUN npm install --only=production
COPY --from=build /app ./
#CMD ["serve", "-s", "dist", "-p", "8080"]
CMD ["node", "server.js"]
# docker build -t image_name .
# docker tag a69905a3f40c sandeep540/node-mongo
# docker push sandeep540/node-mongo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment