Skip to content

Instantly share code, notes, and snippets.

@praveenweb
Created February 7, 2018 11:47
Show Gist options
  • Save praveenweb/acd27014e6d244c3194d3e9d7da04e17 to your computer and use it in GitHub Desktop.
Save praveenweb/acd27014e6d244c3194d3e9d7da04e17 to your computer and use it in GitHub Desktop.
# ---- Base Node ----
FROM node:carbon 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 src /app
# Build react/vue/angular bundle static files
# RUN npm run build
# --- Release with Alpine ----
FROM node:8.9-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"]
@L-U-C-K-Y
Copy link

Hi @praveenweb

Many thanks for this multi-stage Dockerfile!

Where would you suggest to add the node user, as this would run under root by default?

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment