Complete Dockerized Deployment (Dev Backend + Prod Backend + React Frontend + MongoDB)
This project demonstrates a complete multi-environment application deployment featuring:
- Dev Backend (Flask)
- Prod Backend (Flask + Gunicorn)
- Frontend (React)
- MongoDB Database
- Docker & Docker Compose Multi-Service Orchestration
- Networking, Environment Handling & Service Communication
This repository fulfills the Multi-Environment Deployment Assessment requirements and includes complete troubleshooting notes.
- Flask development server
- Auto-reload
- Accessible at:
http://localhost:3001
- Flask app served using Gunicorn
- Optimized for production
- Accessible at:
http://localhost:3002
- React application
- Communicates with both dev & prod backends
- Accessible at:
http://localhost:3005
- MongoDB running as a dedicated container
- Shared across dev and prod environments
Both environments include:
GET /health β {"status":"ok"}
multienv_deployment_DEEPIKA_NARENDRAN/ βββ backend β βββ dev β β βββ app.py β β βββ Dockerfile β β βββ requirements.txt β β βββ templates β β βββ index.html β βββ prod β βββ app.py β βββ Dockerfile β βββ requirements.txt β βββ templates β βββ index.html βββ docker-compose.yml βββ frontend β βββ Dockerfile β βββ package.json β βββ public β β βββ favicon.ico β β βββ index.html β β βββ logo192.png β β βββ logo512.png β β βββ manifest.json β β βββ robots.txt β βββ README.md β βββ src β βββ App.css β βββ App.js β βββ App.test.js β βββ index.css β βββ index.js β βββ logo.svg β βββ pages β β βββ Home.css β β βββ Home.js β β βββ Tickets.css β β βββ Tickets.js β βββ setupTests.js βββ LICENSE βββ README.md βββ submission βββ submission-info.txt
Ensure your machine has:
- Docker β₯ 20.x
- Docker Compose β₯ v2.x
- (Optional) Python 3.11+ for local testing
git clone https://github.com/YOUR-USERNAME/MultienvApp.git cd MultienvApp
You are using MongoDB Atlas instead of a local Mongo container.
- Go to https://cloud.mongodb.com
- Create a free/shared cluster
- Create a new database user
- Assign password
- Copy your connection string:
mongodb+srv://<username>:<password>@<cluster>.mongodb.net/
Go to Network Access β Add IP:
0.0.0.0/0 (Allow all)
<Your IP>/32
Dev DB:
multienv_dev
Prod DB:
multienv_prod
(Atlas auto-creates databases on the first write.)
Add to .gitignore:
backend/*/.env
FLASK_DEBUG=1 PORT=3001 MONGO_URI="mongodb+srv://<username>:<password>@<cluster>.mongodb.net/multienv_dev?retryWrites=true&w=majority&appName=MultiEnvApp"
FLASK_DEBUG=0 PORT=3002 MONGO_URI="mongodb+srv://<username>:<password>@<cluster>.mongodb.net/multienv_prod?retryWrites=true&w=majority&appName=MultiEnvApp"
docker compose up --build -d
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
Expected:
multienv_dev_backend Up 0.0.0.0:3001->3001/tcp multienv_prod_backend Up 0.0.0.0:3002->3002/tcp multienv_frontend Up 0.0.0.0:3005->3000/tcp multienv_mongo Up 0.0.0.0:27017->27017/tcp
curl http://localhost:3001/health
curl http://localhost:3002/health
Open in browser:
http://localhost:3005
http://localhost:3005/dev
http://localhost:3005/prod
(All real issues encountered during this deployment)
Error:
bind: address already in use
Changed frontend host port to 3005 in docker-compose.yml:
`ports:
- "3005:3000"`
Mongo logs showed:
Client sent an HTTP request over a native MongoDB connection
This happened because curl http://localhost:27017 was used --- MongoDB uses binary protocol.
Correct mongo connectivity testing:
docker run --rm -it --network multienvapp_multinet mongo:6.0 mongosh "mongodb://mongo:27017" --eval 'db.runCommand({ ping: 1 })'
Result:
{ ok: 1 }
ValueError: You must specify a URI or set the MONGO_URI
Added .env files with MONGO_URI
Ensured env_file: is configured for each backend service.
docker run --rm -it --network multienvapp_multinet mongo:6.0 mongosh --host mongo --eval 'db.runCommand({ ping: 1 })' { ok: 1 }
exec: "gunicorn": executable file not found in $PATH
Added gunicorn to backend/prod/requirements.txt:
gunicorn>=20.1.0
Rebuild:
docker compose build prod-backend
Backends had no /health endpoint.
Added this route:
@app.route("/health") def health(): return jsonify({"status": "ok"}), 200
OptionalMemberAccess
Added:
assert mongo.db is not None
Or:
# type: ignore
| Component | Status | Test |
|---|---|---|
| MongoDB | β running | { ok: 1 } |
| Dev Backend | β running | curl /health |
| Prod Backend | β running | curl /health |
| Frontend | β running | http://localhost:3005 |
| API Communication | β working | Frontend β Backends β Mongo |
| Data Persistence | β working | add/complete/delete todos |
To deploy images professionally, use:
A fully functioning multi-environment Dockerized application backed by MongoDB Atlas, with professional-grade documentation and troubleshooting.
DEEPIKA NARENDRAN Project: Multi-Environment Ticket Management Application
GitHub: @JoinDeeHub