Docker is taking wrong settings file when creating image
I have Django application where my settings are placed in folder named settings. Inside this folder I have init.py, base.py, deployment.py and production.py.
My wsgi.py looks like this:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp_settings.settings.production") application = get_wsgi_application()
Every time I create image Docker is taking settings from development.py instead of production.py. I tried to change my setting using this command:
It works fine when using conda/venv and I am able to switch to production mode however when creating Docker image it does not take into consideration production.py file at all.
Is there anything else I should be aware of that causes issues like this and how can I fix it?
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!
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.