103 lines
3.5 KiB
Markdown
103 lines
3.5 KiB
Markdown
Application Overview
|
||
This web application is a basic Django project connected to a PostgreSQL database.
|
||
|
||
Django web service: Runs a Django development server.
|
||
PostgreSQL database service: Stores data for the Django application.
|
||
The services are configured to communicate with each other over a custom virtual network, and the database data is persisted in a named volume.
|
||
|
||
Project Structure
|
||
The repository contains the following key files:
|
||
|
||
docker-compose.yml: Defines the services (Django and PostgreSQL) and configurations.
|
||
Dockerfile: Defines the configuration for building the Django web service.
|
||
wait-for-it.sh: A script that ensures the Django app waits for PostgreSQL to be ready before starting.
|
||
requirements.txt: Python dependencies for the Django application.
|
||
manage.py: The Django project’s command-line utility.
|
||
prepare-app.sh: Script to prepare the application environment (build images, create volumes, and networks).
|
||
start-app.sh: Script to start the application (launch containers and configure them to restart on failure).
|
||
stop-app.sh: Script to stop the containers (pause the application without resetting the state).
|
||
remove-app.sh: Script to remove all traces of the application (cleanup).
|
||
Virtual Networks and Named Volumes
|
||
Network: mic_default_san
|
||
Custom network for communication between the services.
|
||
Volume: postgres_data
|
||
A named volume used to persist PostgreSQL data so that data is not lost if the container is stopped or removed.
|
||
Container Configuration
|
||
PostgreSQL Service
|
||
Image: postgres:13
|
||
Environment variables:
|
||
POSTGRES_DB: Database name (mydatabase)
|
||
POSTGRES_USER: Database user (myuser)
|
||
POSTGRES_PASSWORD: Database password (mypassword)
|
||
Ports: Exposes PostgreSQL on localhost:5432
|
||
Volume: Persists data in the postgres_data volume.
|
||
Django Web Service
|
||
Build Context: The Dockerfile is used to build the web service container.
|
||
Command: Waits for PostgreSQL to be available before starting the Django development server.
|
||
Ports: Exposes the Django app on localhost:8000
|
||
Environment Variables:
|
||
DATABASE_URL: Connection string for the database.
|
||
Instructions for Running the Application
|
||
Step 1: Prepare the Application
|
||
Run the prepare-app.sh script to build the Docker images, create named volumes, and set up networks.
|
||
|
||
bash
|
||
Copy
|
||
Edit
|
||
./prepare-app.sh
|
||
Step 2: Start the Application
|
||
Run the start-app.sh script to start the application. This will launch the containers, and you can access the web application in your browser.
|
||
|
||
bash
|
||
Copy
|
||
Edit
|
||
./start-app.sh
|
||
After running the script, you will see the following message:
|
||
|
||
arduino
|
||
Copy
|
||
Edit
|
||
The app is available at http://localhost:8000
|
||
Step 3: Open the Web Application
|
||
Open a browser and navigate to http://localhost:8000 to view the Django application.
|
||
Step 4: Stop the Application
|
||
To stop the application without removing containers and volumes, use the stop-app.sh script. This will pause the services but retain the current state.
|
||
|
||
bash
|
||
Copy
|
||
Edit
|
||
./stop-app.sh
|
||
Step 5: Remove the Application
|
||
If you want to completely remove all containers, networks, and volumes created by the application, use the remove-app.sh script.
|
||
|
||
bash
|
||
Copy
|
||
Edit
|
||
./remove-app.sh
|
||
After running the script, everything related to the application will be removed.
|
||
|
||
Example Workflow
|
||
Here’s an example of working with the application:
|
||
|
||
bash
|
||
Copy
|
||
Edit
|
||
# Prepare the application
|
||
./prepare-app.sh
|
||
Preparing app ...
|
||
|
||
# Run the application
|
||
./start-app.sh
|
||
Running app ...
|
||
The app is available at http://localhost:8000
|
||
|
||
# Open the web application in a browser.
|
||
|
||
# Stop the application
|
||
./stop-app.sh
|
||
Stopping app ...
|
||
|
||
# Remove the application
|
||
./remove-app.sh
|
||
Removed app.
|