Home > Mobile >  How to run Dockerized React application in SSR (Server Side Rendering) mode
How to run Dockerized React application in SSR (Server Side Rendering) mode

Time:09-19

I have a React application which runs on Docker container and interacts with .NET Core application running on another container. I want to run my React application in SSR (Server Side Rendering) mode. How can I do it? Should I install Nextjs in React application container?

CodePudding user response:

For this you can build your docker image from nginx. first you have to build your react app. See the following example dockerfile:

FROM nginx:alpine

# adding nginx.conf file to the right place
COPY ./.nginx/nginx.conf /etc/nginx/nginx.conf

#remove default html file
RUN rm -rf /usr/share/nginx/html/*

#Copy index.html to nginx/html dir (this is the first thing request by browser)
COPY --from=builder /react-ui/build /usr/share/nginx/html

EXPOSE 3000 80

ENTRYPOINT ["nginx", "-g", "daemon off;"] 
  • Related