Created
April 15, 2020 12:41
-
-
Save juanje/be3789e2dd3bb2b908f5147bd205569e to your computer and use it in GitHub Desktop.
Dockerfile multi-stage for a minimal production-ready React app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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