Skip to content

Instantly share code, notes, and snippets.

@juanje
Created April 15, 2020 12:41
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 juanje/be3789e2dd3bb2b908f5147bd205569e to your computer and use it in GitHub Desktop.
Save juanje/be3789e2dd3bb2b908f5147bd205569e to your computer and use it in GitHub Desktop.
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
WORKDIR /app
# 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
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment