Complete setup guide for installing Docker on WSL 2 Ubuntu 24.04.
sudo apt update
sudo apt upgrade -ysudo apt install -y ca-certificates curl gnupg lsb-releasesudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpgecho "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullsudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginsudo service docker startsudo docker run hello-worldYou should see: "Hello from Docker!" message.
This allows you to run Docker without sudo:
sudo usermod -aG docker $USERImportant: After this, you need to log out and log back in, or run:
newgrp dockerdocker run hello-worldEdit your .bashrc or .zshrc:
nano ~/.bashrcAdd this at the end:
# Start Docker daemon automatically
if ! service docker status > /dev/null 2>&1; then
sudo service docker start > /dev/null 2>&1
fiEdit sudoers file:
sudo visudoAdd this line at the end:
%docker ALL=(ALL) NOPASSWD: /usr/sbin/service docker start
docker compose versionYou should see something like: Docker Compose version v2.x.x
# Navigate to your project
cd /your-project/django-nextjs-chatbot
# Test Docker
docker --version
docker compose version
# Build and run your project
docker compose up --buildStart Docker:
sudo service docker startStop Docker:
sudo service docker stopCheck Docker Status:
sudo service docker statusRestart Docker:
sudo service docker restartsudo service docker start# Make sure you're in docker group
groups $USER
# If docker is not listed, add yourself again
sudo usermod -aG docker $USER
newgrp dockerCreate/edit .wslconfig in Windows:
# In Windows: C:\Users\YourUsername\.wslconfig
[wsl2]
memory=8GB
processors=4
swap=2GBThen restart WSL from PowerShell (Windows):
wsl --shutdownRun these to confirm everything works:
# Check Docker version
docker --version
# Check Docker Compose
docker compose version
# Check Docker service
sudo service docker status
# Run test container
docker run hello-world
# Check if you can run without sudo
docker psAll set? Let me know if you hit any issues, and I'll help you troubleshoot! 🎯
This guide will help you run the Django + Next.js chatbot using Docker.
- Docker Desktop installed
- Docker Compose installed (comes with Docker Desktop)
- OpenAI API key
Backend:
cd backend
cp .env.example .env
# Edit .env and add your OPENAI_API_KEYFrontend:
cd frontend
cp .env.example .env.local
# Review the settings (defaults should work)Root .env (for docker-compose):
# Create .env in project root
echo "OPENAI_API_KEY=your-actual-openai-key-here" > .env# From project root
docker-compose up --buildThis will:
- Create PostgreSQL database container
- Build and run Django backend on
http://localhost:8000 - Build and run Next.js frontend on
http://localhost:3000
In a new terminal:
docker-compose exec backend python manage.py migratedocker-compose exec backend python manage.py createsuperuser- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- Django Admin: http://localhost:8000/admin
docker-compose updocker-compose up -ddocker-compose down# All services
docker-compose logs -f
# Specific service
docker-compose logs -f backend
docker-compose logs -f frontenddocker-compose up --build# Migrations
docker-compose exec backend python manage.py migrate
# Create app
docker-compose exec backend python manage.py startapp myapp
# Shell
docker-compose exec backend python manage.py shell
# Collect static files
docker-compose exec backend python manage.py collectstatic# Install new package
docker-compose exec frontend npm install package-name
# Run npm command
docker-compose exec frontend npm run build# Access PostgreSQL
docker-compose exec db psql -U chatbot_user -d chatbot_db# Stop and remove containers, networks
docker-compose down
# Also remove volumes (WARNING: deletes database data!)
docker-compose down -v# Change ports in docker-compose.yml
# For example, change "3000:3000" to "3001:3000"# Uncomment WATCHPACK_POLLING in docker-compose.yml
# Or add to frontend/.env.local:
WATCHPACK_POLLING=true# Wait for database to be ready
# The backend service has a healthcheck that waits for PostgreSQL
# If issues persist, try:
docker-compose restart backend# Fix file permissions
sudo chown -R $USER:$USER .docker-compose build --no-cache- Edit code - Changes auto-reload for both Django and Next.js
- Backend changes - Auto-reload with Django's runserver
- Frontend changes - Hot Module Replacement (HMR) with Next.js
- New dependencies:
- Backend: Add to
requirements.txt, thendocker-compose up --build - Frontend:
docker-compose exec frontend npm install
- Backend: Add to
For production, you'll need:
- Separate Dockerfile.prod files
- docker-compose.prod.yml
- Proper SECRET_KEY, DEBUG=0
- Static file serving via Nginx
- Gunicorn for Django
(These will be covered in our YouTube tutorial series!)
Need help? Check out our YouTube tutorials or ask in GitHub Discussions!