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,, and

My 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 instead of I tried to change my setting using this command:

set DJANGO_SETTINGS_MODULE=myapp_settings.settings.production

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 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!

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.

Back to Top