Home > database >  Django deployment with docker - create superuser
Django deployment with docker - create superuser

Time:12-11

I have 3 environments set up and cannot createsuperuser. The way I migrate and runserver now follows the container so I have an entrypoint.sh:

#!/bin/sh
  1
  2 echo "${RTE} Runtime Environment - Running entrypoint."
  3
  4 if [ "$RTE" = "dev" ]; then
  5
  6     python manage.py makemigrations --merge
  7     python manage.py migrate --noinput
  8     python manage.py runserver 0:8000
  9
 10     python manage.py createsuperuser --username "admin" --email "[email protected]" --password "superuser"
 11     echo "created superuser"
 12
 13 elif [ "$RTE" = "test" ]; then
 14
 15     echo "This is tets."
 16     python manage.py makemigrations
 17     python manage.py migrate
 18     python manage.py runserver
 19
 20 elif [ "$RTE" = "prod" ]; then
 21
 22     python manage.py check --deploy
 23     python manage.py collectstatic --noinput
 24     gunicorn kea_bank.asgi:application -b 0.0.0.0:8080 -k uvicorn.workers.UvicornWorker
 25
 26 fi

lines 10/11 is what I want to make work, I think I have a syntax issue. Originally I wanted the password and username to be variables stored in an env file:

1   RTE=dev
  1 POSTGRES_USER=pguser
  2 POSTGRES_PASSWORD=pgpassword
  3 POSTGRES_DB=devdb
  4 DJANGO_SUPERUSER_PASSWORD=superuser
  5 [email protected]
  6 DJANGO_SUPERUSER_USERNAME=admin

But now I just want it to work, I need to create a superuser account in order to develop. Can anyone spot what's wrong? I can see my application on localhost:8000, but how do I create the superuser in this scenario?

CodePudding user response:

According to createsuperuser -h and this doc, createsuperuser command does not support --password flag. to read arguments from environment variables, you should use this command with --noinput flag and set required fields like username, email and password as DJANGO_SUPERUSER_<uppercase_field_name> in your env file.

python manage.py createsuperuser --noinput

  • Related