🚀 LeetCode Clone Setup Guide (Windows + WSL + Docker + PostgreSQL + Judge0)

🚀 LeetCode Clone Setup Guide (Windows + WSL + Docker + PostgreSQL + Judge0)
Audience: CS students and developers building a LeetCode-style code execution platform using Express.js, PostgreSQL, Docker, WSL, and Judge0.
⚙️ Step 1: Setting Up WSL (Windows Subsystem for Linux)
1. Enable WSL
Launch PowerShell as Administrator (right-click Start > Windows PowerShell (Admin)).
Run this command:
wsl --install
This installs WSL with Ubuntu as the default Linux distribution.
2. Restart Your Computer
- WSL setup will prompt you to restart. Go ahead and do it.
3. Finish Ubuntu Setup
Open Ubuntu from the Start menu.
Set your UNIX username and password when prompted.
4. Update Ubuntu
sudo apt update && sudo apt upgrade -y
5. (Optional) Fix Docker compatibility with cgroup settings
sudo nano /etc/default/grub
Change this line:
GRUB_CMDLINE_LINUX="systemd.unified_cgroup_hierarchy=0"
Save & exit (
Ctrl + O
,Enter
, thenCtrl + X
)Run:
sudo update-grub sudo reboot
🐳 Step 2: Install Docker & Docker Compose on Ubuntu
1. Install Docker
sudo apt update && sudo apt install -y docker.io
2. Install Docker Compose
sudo apt install -y docker-compose
3. Start Docker Service (on every boot or manually)
sudo service docker start
🛢️ Step 3: Set Up PostgreSQL Database in Docker
1. Run PostgreSQL in Docker
sudo docker run --name my-postgres \
-e POSTGRES_USER=myuser \
-e POSTGRES_PASSWORD=mypassword \
-p 5432:5432 -d postgres
⚠️ Avoid using special characters in passwords to prevent connection issues.
2. Check Container is Running
sudo docker ps
🔧 Step 4: Configure Prisma with PostgreSQL
1. Install Prisma
npm i prisma @prisma/client
2. Initialize Prisma
npx prisma init
- This creates a
prisma/
folder and.env
file.
3. Configure DATABASE_URL in .env
DATABASE_URL="postgresql://myuser:mypassword@localhost:5432/postgres"
4. Prisma Commands Flow
Generate Prisma Client
npx prisma generate
Creates a client for interacting with your DB.
Create Migration (optional for SQL schema)
npx prisma migrate dev --name init
Creates a new migration and pushes it to the DB.
Push Prisma Schema to DB (no migration file)
npx prisma db push
Directly updates the DB with the schema (quick and dirty).
⚖️ Step 5: Setting Up Judge0 Code Execution Engine in WSL
1. Download Judge0
wget https://github.com/judge0/judge0/releases/download/v1.13.1/judge0-v1.13.1.zip
2. Unzip the Archive
unzip judge0-v1.13.1.zip
cd judge0-v1.13.1
3. Edit Judge0 Configuration
nano judge0.conf
Update the following:
REDIS_PASSWORD=yourredispassword
POSTGRES_PASSWORD=yourdbpassword
🔐 Use strong but simple passwords (no symbols like
@
,$
, etc.).
4. Start Judge0 Services in Docker
Start Redis and PostgreSQL first:
sudo docker-compose up -d db redis
Give it a moment:
sleep 10s
Start remaining services:
sudo docker-compose up -d sleep 5s
5. Verify Installation
Open your browser:
http://localhost:2358/docs
You should see the Swagger API UI of Judge0 ✅
🧠 Pro Tips
Use
Ctrl + C
to stop any running service in the terminal.Use
sudo docker-compose down
to stop and remove containers.Don’t forget to use
sudo service docker start
when you reboot WSL.Use tools like Postman or REST Client to test Judge0 endpoints.
🧾 Final Thoughts
You’ve just built the backend infrastructure of a LeetCode-style app from scratch! Now go ahead and integrate it with Express.js or any frontend of your choice. The real fun (and bugs) begin now 😉
Happy Coding! 💻⚔️
Subscribe to my newsletter
Read articles from Pritam Awatade directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
