Articles → DOCKER → Hosting The React Application On Docker

Hosting The React Application On Docker






VM Creation





Create A React Application





Give Permission Of “App” Folder To Root User




sudo chown -R root:root /home/demouser/app



Create Dockerfile




cd /home/demouser/app




FROM node:14


WORKDIR /home/demouser/app
COPY . .

RUN npm install

RUN npm run build
CMD ["npx", "serve", "-s", "build", "-l", "3000"]



Provide Permissions To Root User To Node_Modules




chmod +x /home/demouser/app/node_modules/.bin/react-scripts



Create A Docker Container




docker build -t my-react-app .



Enable 3000 Port For Inbound And Outbound Port In The Virtual Machine




Picture showing the 3000 port number enabled in inbound port rules
Click to Enlarge

Picture showing the 3000 port number enabled in outbound port rules
Click to Enlarge


Run React Server In Docker




docker run -p 3000:3000 my-react-app



Output


Picture showing the react application deployed on docker
Click to Enlarge




Posted By  -  Karan Gupta
 
Posted On  -  Friday, June 23, 2023

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250