Back to homepage
1.1
π Dockerizing and Deploying React App
This document outlines the steps to dockerize the React frontend and deploy it to Docker Hub.
π Step 1: Create Docker-related Files
1.1
# Build Stage: Install & build the appFROM node:18-alpine AS builderWORKDIR /appCOPY package*.json ./RUN npm installCOPY . .RUN npm run build
Add .dockerignore
node_modulesbuild.dockerignoreDockerfilenginx.conf.git
π³ Step 2: Login to Docker Hub
docker login
Enter your Docker Hub username and password. (once)
π οΈ Step 3: Build Docker Image
docker build -t sabberrahman/image-Name:Tag_name .
π€ Step 4: Push Image to Docker Hub
docker push sabberrahman/frontend_dashboard:latest
π Step 5: Pull and Run Anywhere
docker pull sabberrahman/frontend_dashboard:latestdocker run -p 80:80 sabberrahman/frontend_dashboard:latest
π¦ Optional: Use with Docker Compose
docker-compose.yml
version: '3'services:frontend:image: sabberrahman/frontend_dashboard:latestports:- "80:80"
Run
docker-compose up --build
π§ Notes You can change the image name/tag as needed. Ensure youβre in the project root where your Dockerfile exists. Keep .env or secrets out of the image unless intentionally required.
π Done! You have successfully dockerized, pushed, and deployed your React app.