1) Storing Code
To Deploy Any App we would require some version control storage . In this project i have used github for the same .
The code given is pushed to Githu repository :-https://github.com/kus123123/new-django-app.git
Runnning Link :-http://18.104.22.168:8000/
the github is open source and allows easily to update , fetch and remove code easily
2) Creating a Instance :-
Instance can be created on any cloud . For this I have used EC2 instance with ubuntu OS . and connected to aws using ssh .
3) Configuring instance
The OS is empty with only important software installed . We need to update and install required software:
sudo apt update sudo apt install docker.io sudo usermod -aG docker $USER sudo reboot
now the system is configured we need to pull code from github repository .
github clone https://github.com/kus123123/new-django-app.git
This will clone the app from central repository to local repository .
4) Creating a requirements.txt file :
This file contains all the dependency that are needed to run the django app .
5) Creating a Dockerfile :
dockerfile contains all the instruction we want to create a container .
FROM python:3.9-slim-buster WORKDIR /code COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 8000 CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
This file is creating a python image and creating a code dir .
copying the requirements file in workdir . installing all requirements and copying all code from present directory to /code
and runing server .
6) Building a docker image :
docker build -t kush1231234/mynewapp .
7) Running the container :
docker run -d -p 8000:8000 kush1231234/newapp1
5 ) Pushing all changes to repository
6) Opening ports 8000 on instance to allow traffic .
this is done by going to setting -->launch wizard --> inbound rules
and also make sure To allow in the setting.py .
ALLOWED_HOSTS = ['*']