django superuser created through docker-compose file doesn’t work

  django, docker, docker-compose, python, superuser

I have a simple django-mongo application.
I have a dockerfile for my django application.

I have a docker-compose.yml which contains django and mongo images.
I am able to build and run the django-mongo application using docker-compose commands.

the problem I am facing is I am unable to log into the django admin-panel using superuser credentials.

Below is my dockerfile

FROM python:3.8-alpine

RUN mkdir /cursor_infotech
WORKDIR /cursor_infotech
ADD . /cursor_infotech/

RUN pip install -r requirements.txt

docker-compose.yml

version: "3"
services:
       cursor-infotech:
           container_name: cursor
           image: cursor
           restart: always
           build: .
           #environment:
            #  - MONGO_URI=$MONGO_URI
            #  - PORT=$PORT
            #  - NODE_ENV=$NODE_ENV   
           ports:
              - "7000:7000"
           networks:
              - cursor-backend
           depends_on:
              - mongo
           command: > 
                sh -c "python manage.py makemigrations && python manage.py migrate && 
                python manage.py createsuperuser --noinput --username admin --email [email protected] && gunicorn -b 0.0.0.0:7000 cursor_infotech.wsgi"
       mongo:
             container_name: mongo
             image: mongo  
             environment:
               - MONGO_INITDB_DATABASE=cursor-pcbuild
               - MONGO_INITDB_ROOT_USERNAME=root
               - MONGO_INITDB_ROOT_PASSWORD=password
             volumes:
                - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo-js:ro
                - ./data:/usr/share/db/data
             ports:
                - '27017:27017'
             networks:
                - cursor-backend 
networks:
  cursor-backend:
    driver: bridge

I ran this command in my project folder

docker-compose up --build

The django & mongo images are build and deployed – working fine.

When I try to log-into admin account in my django admin-panel,
I get below error.

django admin panel error

the django superuser I created using docker-compose.yml doesn’t work when I try to log into the django admin-panel.
How to solve this issue?

Source: Docker Questions

LEAVE A COMMENT