DEV Community

Burhan Haroon
Burhan Haroon

Posted on

Deploying a Simple React.js Frontend with Docker Made Easy! πŸš€

Hey, fam! πŸ‘‹ As junior developers, diving into the world of deployment might seem a bit daunting at first, but fear not! Today, I'm here to guide you through deploying a simple React.js frontend with Docker in a breeze. 🌐🐳

Step 1: Get Your React App Ready
Ensure your React app is ready for the big stage! If you don't have one yet, create a basic React app using create-react-app. πŸš€

npx create-react-app dockerized-react-app
cd my-react-app
Enter fullscreen mode Exit fullscreen mode

Step 2: Dockerizing Your React App
Create a file named Dockerfile in your project root. This file tells Docker how to build your app.

# Use an official Node.js runtime as a base image
FROM node:14

# Set the working directory
WORKDIR /usr/src/app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install app dependencies
RUN yarn install

# Copy the app source code
COPY . .

# Expose the port your app will run on
EXPOSE 3000

# Command to run your app
CMD ["yarn", "start"]
Enter fullscreen mode Exit fullscreen mode

Step 3: Build the Docker Image
Open your terminal, navigate to your project directory, and run:

docker build -t dockerized-react-app
Enter fullscreen mode Exit fullscreen mode

This command builds your Docker image with the name dockerized-react-app.

Step 4: Run Your Dockerized React App
Once the image is built, it's time to run your Docker container!

docker run -p 8080:3000 dockerized-react-app
Enter fullscreen mode Exit fullscreen mode

Your React app is now running in a Docker container, accessible at http://localhost:8080 in your browser. πŸŽ‰

Bonus Tip: Simplify Development with Docker Compose
Create a file named docker-compose.yml in your project root:

version: '3'
services:
  web:
    build: .
    ports:
      - "8080:3000"
Enter fullscreen mode Exit fullscreen mode

Run your app with:

docker-compose up
Enter fullscreen mode Exit fullscreen mode

VoilΓ ! Your React app is now deployed using Docker, and you're ready to share it with the world. πŸš€

ReactJS #Docker #WebDevelopment #JuniorDevelopers #TechTips

Feel free to reach out if you have any questions or need further guidance. Happy coding! πŸ’»βœ¨

Image of Quadratic

Python + AI + Spreadsheet

Chat with your data and get insights in seconds with the all-in-one spreadsheet that connects to your data, supports code natively, and has built-in AI.

Try Quadratic free

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay