Good morning.
Can anyone help me with the following problem:
I'm creating a docker-compose from a Django application . I need to create a super user at the moment of the command:
$ docker-compose up
However, I'm not getting it, here is my Dockerfile:
FROM python:3.6.7
ENV PYTHONUNBUFFERED 1
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
I tried to change to:
FROM python:3.6.7
ENV PYTHONUNBUFFERED 1
ENV DJANGO_DB_NAME=default
ENV DJANGO_SU_NAME=admin
ENV [email protected]
ENV DJANGO_SU_PASSWORD=mypass
RUN python -c "import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'projeto.settings'
import django
django.setup()
from django.contrib.auth.management.commands.createsuperuser import get_user_model
if get_user_model().objects.filter(username='$DJANGO_SUPERUSER_USERNAME'):
print 'Super user already exists. SKIPPING...'
else:
print 'Creating super user...'
get_user_model()._default_manager.db_manager('$DJANGO_DB_NAME').create_superuser(username='$DJANGO_SUPERUSER_USERNAME', email='$DJANGO_SUPERUSER_EMAIL', password='$DJANGO_SUPERUSER_PASSWORD')
print 'Super user created...'"
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
But the super admin user was not created and none of the prints appeared in the terminal.
Also, below the file docker-compose.yml:
db:
image: postgres
web:
build: .
command: chmod +x run_web.sh
command: ./run_web.sh
entrypoint: ./entrypoint.sh
volumes:
- .:/code
ports:
- "8000:8000"
links:
- db
run_web.sh:
#!/bin/bash
python manage.py runserver 0.0.0.0:8000
File entrypoint.sh:
#!/bin/sh
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic --noinput
exec "$@"
I tried to include the python manage.py createsuperuser
command in the entrypoint.sh file, but the following error occurred at docker-compose up
:
Superuser creation skipped due to running in a TTY. You can run manage.py createsuperuser
in your project to create one manually.