Django-based “My Notes” Application DeploymentApplication Overview: “My Notes” is a simple note-taking application built using Django. It allows users to create, store, and manage notes, similar to notepad applications used on mobile devices.
Prerequisites:
- Docker & Docker Compose
Ensure Docker and Docker Compose are installed on your machine. These tools will help in containerizing and orchestrating the application and its dependencies. - Django and Gunicorn
Django framework is required to run the web application. Gunicorn is used as the WSGI server for running the Django application in production. - MySQL Database
The application uses MySQL as the database to store notes and user data.
Deployment Steps:
- Docker Compose Setup
The docker-compose.yml file is used to define the services for the application, including:- nginx: The reverse proxy server that handles HTTP requests.
- django_app: The Django application server.
- db: The MySQL database container.
- Dockerfile Configuration
- The Dockerfile is responsible for setting up the environment for both Django and Nginx. Ensure it contains the necessary steps like copying project files, installing dependencies, and configuring the environment.
- Application Build
The following services are configured in docker-compose.yml:- nginx: Acts as a reverse proxy for the application.
- django_app: Hosts the Django application, runs migrations, and starts the Gunicorn server.
- db: The MySQL container holds the data for the application.
- Database Setup
Ensure the MySQL database is initialized with necessary credentials and configurations: - Ports Configuration
- Port 80 for Nginx (HTTP) and port 8000 for Django application.
Ensure no conflicts with other running services on the same ports.
- Port 80 for Nginx (HTTP) and port 8000 for Django application.
- Volumes Configuration
Define volumes to persist data across restarts, especially for MySQL.
volumes: – ./data/mysql/db:/var/lib/mysql - Health Checks
Define health checks for services to ensure they are running correctly:
Running the Application:
Once all configurations are done, the application can be built and deployed using Docker Compose, which will:
- Build the images for all services.
- Start the containers for Nginx, Django, and MySQL.
Troubleshooting Docker Compose and Deployment Issues
1. Address Already in Use Error
2. Container Name Conflict
3. No Permission to Read from Files
4. Memory or Disk Space Issues
5. YAML Formatting Errors in Docker Compose
6. Cannot Find or Read Dockerfile
7. Build Context Issues (e.g., permissions or invalid files)
8. Docker Networking Issues (Binding Ports)
9. Service Dependency Issues
10. File Permission or Volume Mount Issues
Conclusion:
This setup provides a straightforward way to deploy a Django-based “My Notes” application in a containerized environment using Docker and Docker Compose. Ensure that all configurations are correct and monitor the containers for any issues during deployment.
Checkout my GitHub repository, if you like to watch the whole project. https://github.com/Sudoharry/Live-Project-Devops/tree/main/Day02
Source: hashnode.com