Skip to content

Instantly share code, notes, and snippets.

@zbal
Created January 28, 2019 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbal/d4dd88e3f5db92d1934a24a0c9d6875f to your computer and use it in GitHub Desktop.
Save zbal/d4dd88e3f5db92d1934a24a0c9d6875f to your computer and use it in GitHub Desktop.
Dockerfile - Multi step build process for node.js
# One single Dockerfile with a multi step build process
# 1. build all native extensions, dependencies, etc.
# 2. copy resulting files into a clean container
FROM node:10-alpine as builder
# Add core packages to allow building native extensions
RUN apk add --no-cache make gcc g++ python
RUN npm install -g yarn
WORKDIR /src
COPY package.json yarn.lock /src/
RUN yarn install --production
COPY . /src
FROM node:10-alpine
RUN npm install -g pm2
WORKDIR /app
COPY --from=builder /src/ /app/
USER node
EXPOSE 3000
CMD [ "pm2-docker", "--json", "--instances", "0", "server/server.js" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment