'How do I enable Hot reload in react application with Docker?

I am using Docker 20.10.12 and docker-compose v2.2.3 and I want to enable hot reload in my react application, environment windows 11.

My Dockerfile

FROM node:alpine

WORKDIR /app
COPY ./package.json ./
COPY ./package-lock.json ./
RUN npm install

COPY ./ ./

CMD [ "npm", "run", "start" ]

My docker-compose.yml

version: "3"

services:

  frontend:
    build: 
      context: .
      dockerfile: Dockerfile.dev
    environment:
      CHOKIDAR_USEPOLLING: "true"
    volumes:
      - /app/node_modules
      - ./:/app
    ports:
      - 3000:3000

I've even tried to use this command docker run -it -p 3000:3000 -v /app/node_modules -v "$(pwd):/app" sha256:c20d9ef0854b483 but it didn't work.

If you know how I can achieve this, you can help me.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source