🚀 Flask PostgreSQL Docker Setup
This repository provides a production-ready Flask backend application running with Gunicorn and connected to PostgreSQL using Docker networking.
It is designed for clean deployment, easy scalability, and DevOps-friendly workflows.
🐳 1. Pull Required Images
docker pull postgres:15
docker pull varshithchand/flask-app
🌐 2. Create Docker Network
docker network create mynetwork
🗄️ 3. Run PostgreSQL Container
docker run -d --name postgres_db
--network mynetwork
-e POSTGRES_USER=postgres
-e POSTGRES_PASSWORD=password
-e POSTGRES_DB=mydb
-p 5432:5432 postgres:15
🚀 4. Run Flask Application (Gunicorn)
docker run -d --name flask_app
--network mynetwork
-p 5000:5000 varshithchand/flask-app
🌐 5. Access Application
📡 API Endpoints
GET /users
→ Fetch all users
POST /users
→ Add new user
DELETE /users/
→ Delete user
⚙️ Database Configuration (IMPORTANT)
Your Flask app uses:
postgresql://postgres:password@postgres_db:5432/mydb
✔ postgres_db → container name
✔ same Docker network required
🧠 How It Works
postgres_db containerflask_app container using Gunicornmynetwork🛑 Stop & Remove Containers
docker stop flask_app postgres_db
docker rm flask_app postgres_db
🔥 Full Reset (Clean Setup)
docker rm -f flask_app postgres_db
docker volume prune -f
docker network rm mynetwork
⚠️ Common Issues & Fixes
❌ Container exits immediately
👉 Check logs:
docker logs flask_app
❌ Database connection error
✔ Ensure:
❌ Port already in use
👉 Use different port:
docker run -d -p 5001:5000 ...
🚀 Recommended Next Step
Use Docker Compose for better setup:
docker-compose up --build
✔ Auto networking
✔ Dependency handling
✔ Cleaner workflow
👨💻 Author
Varshith Chand
Aspiring DevOps Engineer 🚀give an option to copy paste the commands
Content type
Image
Digest
sha256:e0475493e…
Size
417.2 MB
Last updated
5 months ago
docker pull varshithchand/flask-backend