How to Run a React App in a Docker Container

By Prem Tiwari in Docker Tutorial. Updated on


How to Run a React App in a Docker Container

In this tutorial, I am going to explain the simple and easy steps to run a React App in a docker container.

First you need to create an empty react application by following this create-react-app steps. Once you have created the sample react app, the follow the below steps:

  1. Install create-react-app by following command (npm install create-react-app --global)
  2. Create a new React app ( create-react-app react-docker-app)
  3. Go to the react-docker-app folder and run it, to make sure all is good. (cd react-docker-app && yarn start )

That’s all. Now jump to create a Dockerfile file on root directory of your project. Below is the sample code for Dockerfile.

Now build the image, you can run the following command from the project root folder, where your Docker-file is:

Finally, run this container now. To run it locally, you need to provide the name of the image and the port we want the React app to be accessible on. Note that we used port 80 in the serve command, so need to make sure to use 80 when specifying the container port like this:

Now you can access you react application using http://localhost:8080

Sharing is caring!


Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

You might also like:

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.