Skip to content

Commit bdf532e

Browse files
authored
Merge pull request #56 from Satvik-Singh192/feat/new_docker
feat: dockerized the whole , single command run available now
2 parents 96c45c1 + 29d841f commit bdf532e

File tree

8 files changed

+139
-1
lines changed

8 files changed

+139
-1
lines changed

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,71 @@ MailMERN/
9999
git clone https://github.com/OPCODE-Open-Spring-Fest/MailMERN.git
100100
cd MailMERN
101101
```
102+
103+
## 🐳 Run with Docker (Recommended for Development & Testing)
104+
105+
You can now easily run the entire **MailMERN** stack (Frontend + Backend + MongoDB) using **Docker Compose** — no manual setup needed!
106+
107+
---
108+
109+
### 1️⃣ Prerequisites
110+
Make sure you have these installed:
111+
- [Docker](https://docs.docker.com/get-docker/)
112+
- [Docker Compose](https://docs.docker.com/compose/install/)
113+
114+
---
115+
116+
### 2️⃣ Setup Environment Variables
117+
Create a `.env` file inside the `backend/` folder (if not already present):
118+
119+
```env
120+
PORT=5000
121+
MONGO_URI=mongodb://mongo:27017/mailmern
122+
123+
EMAIL_PASS=your_app_password
124+
OPENAI_API_KEY=your_openai_key
125+
126+
SMTP_HOST=smtp.gmail.com
127+
SMTP_PORT=587
128+
SMTP_SECURE=false # true for 465, false for 587
129+
130+
SMTP_PASS=your_app_password
131+
EMAIL_FROM="MailMERN [email protected]"
132+
133+
NODE_ENV=development
134+
```
135+
136+
### 3️⃣ Start the Containers
137+
138+
From the project root, run:
139+
140+
```bash
141+
docker-compose up --build
142+
```
143+
144+
This will:
145+
146+
🧩 Start the MongoDB container
147+
148+
⚙️ Run the Express backend on port 5000
149+
150+
💻 Serve the React frontend on port 5173
151+
152+
Once started:
153+
154+
Frontend: http://localhost:5173
155+
156+
Backend API: http://localhost:5000/api
157+
158+
### 4️⃣ Stopping Containers
159+
160+
To stop and remove all running containers, use:
161+
162+
```bash
163+
docker-compose down
164+
```
165+
---
166+
## Individual Setup
102167
2️⃣ Backend Setup
103168
```bash
104169
cd backend
@@ -112,6 +177,7 @@ [email protected]
112177
EMAIL_PASS=your_app_password
113178
OPENAI_API_KEY=your_openai_key
114179
```
180+
115181
Run the backend:
116182
```bash
117183
npm run dev

backend/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
npm-debug.log
3+
.DS_Store

backend/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:22-alpine
2+
3+
WORKDIR /app
4+
5+
COPY package*.json ./
6+
RUN npm install
7+
8+
COPY . .
9+
10+
EXPOSE 5000
11+
12+
CMD ["npm", "run", "dev"]

backend/src/server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const userRoutes = require('./routes/userRoutes');
66
const { errorMiddleware } = require('./middlewares/errorMiddleware');
77
const chatbotRoutes = require('./routes/chatbotRoutes');
88
const emailRoutes = require('./routes/emailRoutes');
9+
const googleRoutes = require('./routes/googleRoute');
910
const trackRoutes = require('./routes/trackRoutes');
1011
const { configDotenv } = require('dotenv');
1112
const contactRoutes = require('./routes/contactRoutes');

docker-compose.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
services:
2+
mongo:
3+
image: mongo:6
4+
container_name: mongo
5+
restart: always
6+
ports:
7+
- "27017:27017"
8+
volumes:
9+
- mongo_data:/data/db
10+
11+
backend:
12+
build: ./backend
13+
container_name: mailmern_backend
14+
ports:
15+
- "5000:5000"
16+
env_file:
17+
- ./backend/.env
18+
depends_on:
19+
- mongo
20+
volumes:
21+
- ./backend:/app
22+
- /app/node_modules
23+
command: npm run dev
24+
25+
frontend:
26+
build: ./frontend
27+
container_name: mailmern_frontend
28+
ports:
29+
- "5173:5173"
30+
stdin_open: true
31+
tty: true
32+
depends_on:
33+
- backend
34+
volumes:
35+
- ./frontend:/app
36+
- /app/node_modules
37+
command: npm run dev
38+
39+
volumes:
40+
mongo_data:

frontend/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
npm-debug.log
3+
.env
4+
.DS_Store

frontend/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:22-alpine
2+
3+
WORKDIR /app
4+
5+
COPY package*.json ./
6+
RUN npm install
7+
8+
COPY . .
9+
10+
EXPOSE 5173
11+
12+
CMD ["npm", "run", "dev"]

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7-
"dev": "vite",
7+
"dev": "vite --host 0.0.0.0",
88
"build": "vite build",
99
"lint": "eslint .",
1010
"preview": "vite preview"

0 commit comments

Comments
 (0)