commit 9b52815bce8aaacd70a04eaecf58395489e231f4 Author: Sabareesan Date: Wed Apr 1 01:06:29 2026 +0200 Docker web app project diff --git a/README.md b/README.md new file mode 100644 index 0000000..ded6492 --- /dev/null +++ b/README.md @@ -0,0 +1,61 @@ +# ๐Ÿš€ Docker Multi-Container Web Application + +## ๐Ÿ“Œ Project Overview +This project demonstrates the deployment of a multi-container web application using Docker. + +It includes: +- Frontend (Nginx) +- Backend (Node.js) +- Database (MongoDB) +- Mongo Express (DB UI) + +--- + +## ๐Ÿ—๏ธ Architecture +Browser โ†’ Frontend โ†’ Backend โ†’ MongoDB + +--- + +## โš™๏ธ Technologies Used +- Docker +- Docker Compose +- Node.js +- MongoDB +- Nginx + +--- + +## ๐Ÿ“ฆ Services and Ports + +| Service | Port | +|----------------|------| +| Frontend | 8080 | +| Backend | 3000 | +| MongoDB | 27017 | +| Mongo Express | 8081 | + +--- + +## ๐Ÿ› ๏ธ Setup + +### Prepare +./prepare-app.sh + +### Start +./start-app.sh + +### Stop +./stop-app.sh + +### Remove +./remove-app.sh + +--- + +## ๐Ÿ’พ Persistence +MongoDB uses Docker volume (mongo-data), so data is ู…ุญููˆุธ after restart. + +--- + +## ๐Ÿ‘จโ€๐Ÿ’ป Author +Sabareesan diff --git a/Z1/backend/Dockerfile b/Z1/backend/Dockerfile new file mode 100644 index 0000000..e8d1758 --- /dev/null +++ b/Z1/backend/Dockerfile @@ -0,0 +1,12 @@ +FROM node:18 + +WORKDIR /app + +COPY package.json . +RUN npm install + +COPY . . + +EXPOSE 3000 + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/Z1/backend/package.json b/Z1/backend/package.json new file mode 100644 index 0000000..aa079c4 --- /dev/null +++ b/Z1/backend/package.json @@ -0,0 +1,9 @@ +{ + "name": "backend", + "version": "1.0.0", + "dependencies": { + "express": "^4.18.2", + "mongoose": "^7.0.0", + "cors": "^2.8.5" +} +} \ No newline at end of file diff --git a/Z1/backend/server.js b/Z1/backend/server.js new file mode 100644 index 0000000..38b43fd --- /dev/null +++ b/Z1/backend/server.js @@ -0,0 +1,31 @@ +const express = require("express"); +const mongoose = require("mongoose"); + +const app = express(); +app.use(express.json()); + +const cors = require("cors"); +app.use(cors()); + +mongoose.connect("mongodb://mongo:27017/mydb") + .then(() => console.log("MongoDB connected")) + .catch(err => console.log(err)); + +const Item = mongoose.model("Item", { name: String }); + +app.get("/", (req, res) => { + res.send("Backend running ๐Ÿš€"); +}); + +app.post("/add", async (req, res) => { + const item = new Item({ name: req.body.name }); + await item.save(); + res.send(item); +}); + +app.get("/items", async (req, res) => { + const items = await Item.find(); + res.send(items); +}); + +app.listen(3000, () => console.log("Server running on port 3000")); \ No newline at end of file diff --git a/Z1/docker-compose.yml b/Z1/docker-compose.yml new file mode 100644 index 0000000..ed1414d --- /dev/null +++ b/Z1/docker-compose.yml @@ -0,0 +1,36 @@ +version: "3.9" + +services: + + frontend: + image: nginx:latest + ports: + - "8080:80" + volumes: + - ./frontend:/usr/share/nginx/html + depends_on: + - backend + + backend: + build: ./backend + ports: + - "3000:3000" + depends_on: + - mongo + + mongo: + image: mongo:6 + volumes: + - mongo-data:/data/db + ports: + - "27017:27017" + + mongo-express: + image: mongo-express + ports: + - "8081:8081" + depends_on: + - mongo + +volumes: + mongo-data: \ No newline at end of file diff --git a/Z1/frontend/index.html b/Z1/frontend/index.html new file mode 100644 index 0000000..5992882 --- /dev/null +++ b/Z1/frontend/index.html @@ -0,0 +1,155 @@ + + + + +Docker Web App + + + + + + +
+

๐Ÿš€ Docker App

+ + + +
+ + +
+ + + +
+
+ + + + + \ No newline at end of file diff --git a/Z1/prepare-app.sh b/Z1/prepare-app.sh new file mode 100644 index 0000000..8cd1b19 --- /dev/null +++ b/Z1/prepare-app.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "Preparing application..." + +docker network create app-network 2>/dev/null + +docker volume create mongo-data + +docker-compose build + +echo "Preparation done โœ…" \ No newline at end of file diff --git a/Z1/remove-app.sh b/Z1/remove-app.sh new file mode 100644 index 0000000..2b3cb1c --- /dev/null +++ b/Z1/remove-app.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +echo "Removing application..." + +docker-compose down -v +docker volume rm mongo-data 2>/dev/null +docker network rm app-network 2>/dev/null + +echo "All removed ๐Ÿงน" \ No newline at end of file diff --git a/Z1/start-app.sh b/Z1/start-app.sh new file mode 100644 index 0000000..aa5791f --- /dev/null +++ b/Z1/start-app.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +echo "Starting application..." + +docker-compose up -d + +echo "Application started ๐Ÿš€" +echo "Frontend: http://localhost:8080" +echo "Backend: http://localhost:3000" +echo "Mongo Express: http://localhost:8081" \ No newline at end of file diff --git a/Z1/stop-app.sh b/Z1/stop-app.sh new file mode 100644 index 0000000..8bd39f1 --- /dev/null +++ b/Z1/stop-app.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo "Stopping application..." + +docker-compose down + +echo "Application stopped โœ…" \ No newline at end of file diff --git a/Z1/๐Ÿ“˜ Docker.docx b/Z1/๐Ÿ“˜ Docker.docx new file mode 100644 index 0000000..a2b8c27 Binary files /dev/null and b/Z1/๐Ÿ“˜ Docker.docx differ