This repository contains instructions on how to Dockerize a Django application for easy development and deployment.
py -m venv env
env/Scripts/activate
py -m pip install django
py -m pip freeze > requirements.txt
django-admin startproject setup
py manage.py startapp blog
#Use the official Python image as the base image
FROM python:3.8
#Set environment variable for unbuffered Python output
ENV PYTHONBUFFERED=1
#Set the working directory in the container
WORKDIR /django
#Copy the requirements file into the container
COPY requirements.txt requirements.txt
#Install project dependencies
RUN pip install -r requirements.txt
#Copy the Django project code into the container
COPY .
#Start the Django application
CMD python manage.py runserver 0.0.0.0:8000
version: "3.8"
services:
app:
build: .
volumes:
- .:/django
ports:
- 8000:8000
image: app:django
container_name: my_first_django_container
command: python manage.py runserver 0.0.0.0:8000
docker-compose build
docker-compose up
http://localhost:8000