DEV Community

Krunal Kanojiya
Krunal Kanojiya

Posted on

Follow 7 Step and Dockerize your ReactJS Project

Follow this steps for dockerize your react project

Steps

1 - Make sure you have Docker installed on your system.
2 - Navigate to your reactjs project directory in the terminal and create a new file called "Dockerfile" without any extension.
3 - Add the following code to the Dockerfile:

FROM node:latest

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]
Enter fullscreen mode Exit fullscreen mode

4 - Run the following command in the terminal to build the Docker image:

docker build -t react-app
Enter fullscreen mode Exit fullscreen mode

5 - Once the build is complete, run the following command to run the Docker container:

docker run -p 3000:3000 react-app
Enter fullscreen mode Exit fullscreen mode

6 - Your reactjs app should now be running in a Docker container and available at http://localhost:3000

7 - If you want to make changes to your code and see the changes reflected in the app, run the following command in the terminal to start a development server:

docker compose up
Enter fullscreen mode Exit fullscreen mode

This will start a development server that will automatically update the app as you make changes to the code.

Top comments (0)