[Answered ]-Docker is taking wrong settings file when creating image

1👍

YES, there is something else you need to check:

When you run your docker container you can specify environment variables.
If you declare environment variable DJANGO_SETTINGS_MODULE=myapp_settings.development it will override what you specified inside of wsgi.py!

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp_settings.settings.production")

code above basically means: declare "myapp_settings.settings.production" as the default but if environment variable DJANGO_SETTINGS_MODULE is declared, take the value of that variable.

Edit 1

Maybe you can try specifying the environment variable inside your docker-compose file:

version: '3'

services:
  app:
    environment:
      - DJANGO_SETTINGS_MODULE=myapp_settings.settings.production
    container_name: myapp_django_app
    build:
      context: ./backend
      dockerfile: Dockerfile
    restart: always
    command: gunicorn myapp_settings.wsgi:application --bind 0.0.0.0:80
    networks:
      - myapp_default
    ports:
      - "80:80"
    env_file:
      - ./.env

Leave a comment