Friday, February 21, 2025

Deploy Reactjs Docker container on Ubuntu using GitHub Actions

 

Prerequisites:

  1. An Ubuntu server with Docker installed.
  2. In Firewall Allow Inbound Port (SSH-22) (Reactjs-3009)
  3. A GitHub repository containing your React app.
  4. A Docker Hub account (or a private registry).
  5. SSH access to the Ubuntu server.


Step 1) Install Docker on Ubuntu


Step 2) Create a Dockerfile on your Project


Step 3) Configure GitHub Actions Workflow

  • In your GitHub repo, go to .github/workflows/ and create a new YAML file:


Step 4) Configure GitHub Secrets For Ubuntu SSH and Dockerhub

Go to your GitHub repository 👉 Settings 👉 Secrets and variables 👉 Actions 👉 New repository secret and add:

  • EC2_HOST: Your EC2 public IP.
  • EC2_USER: Your EC2 username (ubuntu)
  • EC2_SSH_KEY: EC2 Pem File Or Your EC2 SSH key
  • DOCKER_USERNAME: Your DockerHub User Name
  • DOCKER_PASSWORD: Your DockerHub Password


Step 5) Verify Deployment

  • Your React app should be live at http://ec2-public-ip:3009


Step 6) Configure Nginx on Ubuntu (Optional)

  • sudo apt install nginx -y
  • sudo nano /etc/nginx/sites-available/react-app

Add This:

Enable the config:

  • sudo ln -s /etc/nginx/sites-available/react-app /etc/nginx/sites-enabled/
  • sudo nginx -t
  • sudo systemctl restart nginx


No comments:

Post a Comment

testing