Dockerfile
# The Dockerfile acts as a blueprint that tells Docker how to build the image,
# including setting up the base environment, installing dependencies, and
# defining the command to start your application.
# Use an official Python runtime as the base image
FROM python:3.13.2-slim
# Prevent Python from writing pyc files and buffer output
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set the working directory in the container to /app
WORKDIR /app
# Copy the requirements file into the container
COPY requirements.txt /app/
# Install the Python dependencies
RUN pip install -r requirements.txt
# Copy the Django project code into the container
COPY . /app
# Collect static files for the Django application
RUN python manage.py collectstatic --noinput
# Expose port 8000 for the Django development server
EXPOSE 8000
# Run the Django development server
CMD ["gunicorn", "student_management.wsgi:application", "--bind", "0.0.0.0:8000"]docker-compose.yml
version: '3.9' # Docker Compose version
services:
web: # Name of the service (like a container)
build: . # Build the Docker image using the Dockerfile in the current directory
ports:
- "8000:8000" # Map port 8000 on your VPS to port 8000 inside the container
volumes:
- .:/app # Sync current folder (host) with /app folder inside the container (for live code changes)
command: python manage.py runserver 0.0.0.0:8000 # Command to run the Django server inside the containerThis reads your Dockerfile and creates a Docker image.
docker-compose buildThe -d flag runs containers in the background (detached mode).
docker-compose up -dIf VPS IP Address is 134.209.159.172, Go to terminal and type
ssh root@134.209.159.172
ssh root@youripaddress
sudo apt update && sudo apt upgrade -ysudo apt install docker.io -y
sudo systemctl enable --now docker
sudo apt install docker-compose -ydocker --version
docker-compose --versioncd /var/wwwgit clone https://github.com/yourusername/yourproject.git
cd yourprojectcd yourprojectdocker-compose builddocker-compose up -dsudo apt install nginx -ynano /etc/nginx/sites-available/mydjangoserver {
listen 80;
server_name hindivoicetyping.com www.hindivoicetyping.com;
location /static/ {
alias /var/www/DjangoStudentManagement/staticfiles/;
}
location /media/ {
alias /var/www/DjangoStudentManagement/media/;
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}To Save Press Ctrl + X, Enter
sudo ln -s /etc/nginx/sites-available/mydjango /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginxhttp://your_vps_ip:8000DEBUG = False
In settings.py update the following:
DEBUG = False
ALLOWED_HOSTS = ['localhost', '127.0.0.1','134.209.159.172','hindivoicetyping.com']
# Static files settings
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
# Media files (for uploaded images)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d hindivoicetyping.com -d www.hindivoicetyping.com
sudo nginx -t
sudo systemctl reload nginxCSRF_TRUSTED_ORIGINS = ['https://hindivoicetyping.com']