Skip to content

Instantly share code, notes, and snippets.

Created Apr 15, 2020
What would you like to do?
Dockerfile multi-stage for a minimal production-ready React app
# Multistage Dockerfile
# STEP 1: build the Reac static files
FROM node:13.2.0-alpine as builder
# Create app directory and set a current directory
# Copy the dependencies files
COPY package.json package-lock.json /app/
# Just install the production packages
ENV NODE_ENV production
# --no-optional not to try compile fsevent package
# That package is only needed on MacOS
RUN npm ci --no-optional
# Copy project files into the docker image
COPY . /app/
RUN npm run build
# STEP 2: copy the static files and serve them with NGINX
FROM nginx:stable-alpine
# From 'builder' copy website to default nginx public folder
COPY --from=builder /app/build /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment