...
To create the Docker volume, on the host:
Code Block docker volume create <volume name>
When running the container, the volume is mounted using the -v
switch. The syntax for this switch is:
Code Block |
---|
-v <volume name>:<path to mount> |
Establishing database file
After the first time python3 manage.py migrate
has been run,
Transfer the
db.sqlite3
file to the mounted volume.Delete the
db.sqlite3
file from its default location at the project root folder.Create a symlink at the project root folder called
db.sqlite3
that points to the file on the mounted volume.
Database connection using entrypoint.sh
It is recommended that the entrypoint.sh
script is used to establish the database connection. The general sequence in the entrypoint.sh
script to connect the database on the volume is:
Run
makemigrations
/migrate
. This creates adb.sqlite3
database file in its default location in the project root folder.Delete the
db.sqlite3
file from the project root folder.Create a symlink to the database folder.
Here is an example of an entrypoint.sh
script:
Code Block |
---|
#!/bin/bash
# Ensure the log directory exists
mkdir -p /var/log/django
# Redirect stdout and stderr to the log file
exec >> /var/log/django/entrypoint.log 2>&1
python3 manage.py makemigrations
python3 manage.py migrate
rm /opt/ece_li_scheduling/db.sqlite3
ln -s /var/lib/ece_li_scheduling/db.sqlite3 /opt/ece_li_scheduling/db.sqlite3
python3 manage.py runserver 0.0.0.0:8000 |
Start First App
Navigate to the root directory of the Django project (where the
manage.py
file is located).Use
manage.py
to initialize the app:Code Block python3 manage.py startapp <app name>
...