How to Dockerize a React App

How to Dockerize a React App

·

1 min read

Let's learn about it.

PREREQUISITES:

  • Docker-Desktop should be installed.

  • An Internet Connection is a must.

STEP 1:Create a file with the name "Dockerfile. dev" in your react app directory.

STEP 2: Write the given commands in Dockerfile.dev

STEP 3:Create a .dockerignore file in the same directory

STEP 4: Write the name of these files in.dockerignore file

STEP 5: Write this command to build your image

  • docker build -f Dockerfile.dev -t reactapp

    NOTE: reactapp is just the name of the image given by us. You can use any random name of your choice

  • docker images --command to check whether the image has been made or not

STEP 6:Run the image(Container creation)

  • docker run -d -p 3005:3000 reactapp

docker ps -- command to check the running containers

3005--is the localhost port of our device on which we want the container to run.

3000--is the default port of our ReactApp

STEP 7:Write localhost:3005 in your search engine.

Congrats your react app is running on your localhost:3005.

THANK YOU FOR READING THIS ARTICLE