Docker

[Docker] React.js + Nginx

When you deploy your React.js application through Docker, you can deploy with Nginx.

The basic principle is, first build a React.js application and move the generated files to “share/nginx/html” in the container.

You are just replacing the default Nginx welcoming page to your React.js application.

Now you just need to run Nginx.

Please check the Docker file below.

Check the sample project

# build environment
FROM node:9.6.1 as builder
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json
RUN npm install --silent
RUN npm install react-scripts@1.1.1 -g --silent
COPY . /usr/src/app
RUN npm run build

# production environment
FROM nginx:1.13.9-alpine
COPY --from=builder /usr/src/app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]