DEV Community

Norman
Norman

Posted on

Hosting React with nginx+docker

Create sample app.

npx create-react-app my-app
cd my-app
npm start
Enter fullscreen mode Exit fullscreen mode

Create Dockerfile.

FROM node:18-alpine

WORKDIR /react-docker-example/

COPY public/ /react-docker-example/public
COPY src/ /react-docker-example/src
COPY package.json /react-docker-example/

RUN npm install

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

Build and run docker image.

docker image build -t my-app-image:latest .
docker run -dp 65535:3000 --name my-app-container my-app-image:latest
Enter fullscreen mode Exit fullscreen mode

You can display app in a browser at the following URL.

http://<your-ip>:65535

Top comments (0)