Skip to content

Instantly share code, notes, and snippets.

@ZealousMacwan
Last active November 19, 2022 17:19
Show Gist options
  • Save ZealousMacwan/74717dfa4104f0ce53d595b3c2e1d5cb to your computer and use it in GitHub Desktop.
Save ZealousMacwan/74717dfa4104f0ce53d595b3c2e1d5cb to your computer and use it in GitHub Desktop.
React Dockerfile for development and production
#development build
FROM node:18.12.1-alpine as development
ENV NODE_ENV development
WORKDIR /react-app
COPY package*.json .
#RUN yarn config set "strict-ssl" false -g
RUN yarn config set registry https://registry.npmjs.org
RUN yarn install
COPY . .
EXPOSE 3000
CMD [ "yarn", "start" ]
#production build
FROM node:18.12.1-alpine as production_builder
ENV NODE_ENV production
WORKDIR /react-app
COPY package*.json .
#RUN yarn config set "strict-ssl" false -g
RUN yarn config set registry https://registry.npmjs.org
#--prodcution overrides the NODE_ENV
RUN yarn install --production
COPY . .
RUN yarn build
#production image
FROM nginx:1.22.1-alpine as production
ENV NODE_ENV production
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
COPY --from=production_builder /react-app/build /usr/share/nginx/html
# Expose port
EXPOSE 80
# Start nginx
CMD ["nginx", "-g", "daemon off;"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment