Skip to content

Instantly share code, notes, and snippets.

@kunokdev
Last active August 24, 2020 14:19
Show Gist options
  • Save kunokdev/109010c082d57ac1310d22e754a19471 to your computer and use it in GitHub Desktop.
Save kunokdev/109010c082d57ac1310d22e754a19471 to your computer and use it in GitHub Desktop.
Lightweight and performant container that serves CRA application with runtime environment variable configuration
# => Build container
FROM node:alpine as builder
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn
COPY . .
RUN yarn build
# => Run container
FROM nginx:1.15.2-alpine
# Nginx config
RUN rm -rf /etc/nginx/conf.d
COPY conf /etc/nginx
# Static build
COPY --from=builder /app/build /usr/share/nginx/html/
# Default port exposure
EXPOSE 80
# Copy .env file and shell script to container
WORKDIR /usr/share/nginx/html
COPY ./env.sh .
COPY .env .
# Make our shell script executable
RUN chmod +x env.sh
# Start Nginx server
CMD ["/bin/sh", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment