Complete Guide: Deploy Django + Docker + PostgreSQL for FREE using Render + Neon.tech

 

Complete Guide: Deploy Django + Docker + PostgreSQL for FREE using Render + Neon.tech

This guide helps you create a simple Django app, containerize it with Docker, connect it to a free PostgreSQL database (Neon.tech), and deploy it on Render — completely FREE and professional.


1. Create a Simple Django Project

Install required packages

pip install django psycopg2-binary gunicorn

Create project

django-admin startproject myproject
cd myproject

Start the development server

python manage.py runserver

2. Create a PostgreSQL Database on Neon.tech (Forever Free)

  1. Go to https://neon.tech

  2. Create a free account

  3. Click Create a Project

  4. Choose PostgreSQL

  5. Copy these details:

    • DATABASE_NAME

    • DATABASE_USER

    • PASSWORD

    • HOST

    • PORT

    • Connection string

Add these in your Django settings:

In settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'your_db_name',
        'USER': 'your_db_user',
        'PASSWORD': 'your_password',
        'HOST': 'your_neon_host',
        'PORT': '5432',
    }
}

3. Containerize Django With Docker

Create a file named Dockerfile:

FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["gunicorn", "myproject.wsgi:application", "--bind", "0.0.0.0:8000"]

Create requirements.txt:

django
gunicorn
psycopg2-binary

Create Docker Compose file (optional):

services:
  web:
    build: .
    ports:
      - "8000:8000"
    env_file:
      - .env

4. Deploy Django on Render (Forever Free)

Step-by-step:

  1. Go to https://render.com

  2. Create a free account

  3. Click New → Web Service

  4. Connect your GitHub repo

  5. Choose:

    • Environment: Docker

    • Region: Any

    • Plan: Free

Render automatically detects your Dockerfile.

Add these Environment Variables in Render:

DATABASE_URL=postgres://user:password@host/dbname
PYTHONUNBUFFERED=1
PORT=8000

(Use Neon connection URL)

Start Command (Render auto-handles from Dockerfile):

gunicorn myproject.wsgi:application --bind 0.0.0.0:$PORT

Render will:

  • Build the Docker image

  • Run your Django app

  • Provide a free HTTPS URL


5. Static Files & Media Handling

Use Cloudinary (free 25GB):

  1. Create account → https://cloudinary.com

  2. Install SDK:

pip install django-cloudinary-storage
  1. Update settings.py:

INSTALLED_APPS += ['cloudinary', 'cloudinary_storage']

DEFAULT_FILE_STORAGE = 'cloudinary_storage.storage.MediaCloudinaryStorage'
STATICFILES_STORAGE = 'cloudinary_storage.storage.StaticHashedCloudinaryStorage'

6. Final Deployment Checklist

Task Status
Django project created ✔️
Dockerfile added ✔️
Neon PostgreSQL created ✔️
Environment variables added ✔️
Deploy on Render free plan ✔️
Cloudinary set up for media ✔️
Application live with HTTPS ✔️

🎉 Your Django App Is Now Live — 100% Free, No Expiry!

This setup uses:

  • Render for hosting (free)

  • Neon.tech for PostgreSQL (free)

  • Cloudinary for media storage (free)

  • Docker for professional deployment

Comments

Popular posts from this blog

Complete Django Deployment on AWS - Complete Guide