Created
June 2, 2021 10:41
-
-
Save ricardodantas/a950a83e057defae905850fd9459d8e1 to your computer and use it in GitHub Desktop.
Dockerfile for a Nginx + React app
This file contains hidden or 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
# Multi-stage | |
# 1) Node image for building frontend assets | |
# 2) nginx stage to serve frontend assets | |
# Name the node stage "builder" | |
FROM node:10 AS builder | |
# Set working directory | |
WORKDIR /app | |
# Copy all files from current directory to working dir in image | |
COPY . . | |
# install node modules and build assets | |
RUN yarn install && yarn build | |
# nginx state for serving content | |
FROM nginx:alpine | |
# Set working directory to nginx asset directory | |
WORKDIR /usr/share/nginx/html | |
# Remove default nginx static assets | |
RUN rm -rf ./* | |
# Copy static assets from builder stage | |
COPY --from=builder /app/build . | |
# Containers run nginx with global directives and daemon off | |
ENTRYPOINT ["nginx", "-g", "daemon off;"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment