title: Django separate settings files in Docker
body: <p>Following <a href="https://medium.com/@ayarshabeer/django-best-practice-settings-file-for-multiple-environments-6d71c6966ee2" rel="nofollow noreferrer">multiple</a> <a href="https://blog.apptension.com/2017/11/09/django-settings-for-multiple-environments/" rel="nofollow noreferrer">articles</a> <a href="https://simpleisbetterthancomplex.com/tips/2017/07/03/django-tip-20-working-with-multiple-settings-modules.html" rel="nofollow noreferrer">around</a> the web, I've split my Django 1.11 <code>settings.py</code> file into multiple files, <code>base.py</code>, <code>local.py</code>, <code>staging.py</code>, <code>production.py</code>, in a <code>settings</code> folder.</p>
  
  <p>The Django app runs in a Docker container.</p>
  
  <p><strong>docker-compose.yml</strong>:</p>
  
  <pre><code>django:
      build:
        context: .
      env_file: .env
      command: ["/wait-for-it.sh", "mariadb:3306", "--", "/gunicorn.sh"]
  </code></pre>
  
  <p>In the <code>Dockerfile</code> I export the <code>DJANGO_SETTINGS_MODULE</code> as the <code>local</code> settings file (which in turn imports the <code>base.py</code> settings file).</p>
  
  <p><strong>Dockerfile</strong>:</p>
  
  <pre><code>FROM python:3.6.4
  RUN mkdir /app
  ADD requirements/*.txt app/requirements/
  RUN pip install -r mira/requirements/dev.txt
  ADD . /app
  RUN export DJANGO_SETTINGS_MODULE=app.settings.local
  RUN export DJANGO_SECRET_KEY=dummy-secret-key
  COPY ./docker/web/entrypoint.sh ./docker/web/gunicorn.sh ./docker/web/wait-for-it.sh ./docker/web/logging.conf ./scripts/setup.sh /
  RUN chmod +x /entrypoint.sh /gunicorn.sh /wait-for-it.sh /setup.sh
  WORKDIR ./app
  </code></pre>
  
  <p><strong>settings/base.py</strong>:</p>
  
  <pre><code>SECRET_KEY = os.environ['DJANGO_SECRET_KEY']
  </code></pre>
  
  <p><strong>.env</strong>:</p>
  
  <pre><code>DJANGO_SECRET_KEY=FOOBAR
  </code></pre>
  
  <p>When I try to up the container, I get this error:</p>
  
  <blockquote>
    <p>The SECRET_KEY setting must not be empty.</p>
  </blockquote>