How to perform Python Django database migrations when using Docker-Compose?

To perform Python Django database migrations when using Docker-Compose, we can add the migrate command in a script.

For instance, in docker-entrypoint.sh, we add

python manage.py collectstatic --noinput
python manage.py migrate
python manage.py runserver 0.0.0.0:8000

to collect static files with

python manage.py collectstatic --noinput

We run the database migrations with

python manage.py migrate

And then we start the server with

python manage.py runserver 0.0.0.0:8000

Then we run the script during docker-compose by running the script with a command by putting it in the command property.