DEV Community

Cover image for Dockerizing React App
Jun
Jun

Posted on • Edited on

1 1

Dockerizing React App

Written with Cameron Gibson

Versions

Node version: v16.13.0
Docker version: 20.10.12

Link

GitHub Repository
Here’s How to Dockerize React App

Table of Contents

  1. Create React app
  2. Create Dockerfile, image and run the container

1. Create React app

① Create React App following official tutorial
② Run command below

npx create-react-app <app name> # witch is going to be the folder name
cd <app name>
npm start
Enter fullscreen mode Exit fullscreen mode

③ Access to http://localhost:3000
Confirm you can see React app welcome page
localhost:3000_reactapp

④ Stop Running by Ctrl + C

2. Create Dockerfile, image and run the container

① CreateDockerfile in root directory
And copy the code below

# Dockerfile
FROM node:16
WORKDIR /reactapp
ENV PATH /reactapp/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm i
COPY . ./
CMD ["npm", "start"]
Enter fullscreen mode Exit fullscreen mode

② Build image

docker build -t <image name> . 
Enter fullscreen mode Exit fullscreen mode

③ Run container

docker run \
    -it \
    --rm \
    -v ${PWD}:/reactapp \
    -v /reactapp/node_modules \
    -p 3001:3000 \
    -e CHOKIDAR_USEPOLLING=true \
    <image name>:latest
Enter fullscreen mode Exit fullscreen mode

④ Access to http://localhost:3001
Confirm you can see React app welcome page
localhost:3001_reactapp

Image of PulumiUP 2025

Explore What’s Next in DevOps, IaC, and Security

Join us for demos, and learn trends, best practices, and lessons learned in Platform Engineering & DevOps, Cloud and IaC, and Security.

Save Your Spot

Top comments (0)

Image of PulumiUP 2025

Let's talk about the current state of cloud and IaC, platform engineering, and security.

Dive into the stories and experiences of innovators and experts, from Startup Founders to Industry Leaders at PulumiUP 2025.

Register Now

👋 Kindness is contagious

Please consider leaving a ❤️ or a friendly comment if you found this post helpful!

Okay