Go to Production#

In this lab we build on the last two by examining the components of our application and making sure that our built Django container is organized properly.

Source Code#

Where is the source code of our mysite application?

Source code should be located in our project repository, next to the Dockerfile.


Dependencies are the programs (both source and binary) that our software depends on in order to operates. Dependencies can be:

  1. Packages installed on the system.

  2. Language specific packages that are installed (e.g. pip install django)

  3. The versions of other containers

What are the dependencies of our application?

Dependencies are specific to a version of our software and are managed in the Dockerfile.


Configuration is data that’s specific to an instance of our application. Configuration often has to be present in more than one place (e.g. the name of a user) and might be sensitive (e.g. passwords).

What is the configuration of our application?

Configuration is usually implemented with environment variables.

Use Environment Variables in Django#

In the last lab you hard-coded configuration. This is bad! Update your database settings to the following:

import os
    'sqlite': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    'postgres': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('DB_NAME', 'mysite'),
        'USER': os.environ.get('DB_USER', 'postgres'),
        'PASSWORD': os.environ.get('DB_PASSWORD', 'django'),
        'HOST': os.environ.get('DB_HOST', 'postgres'),
DATABASES['default'] = DATABASES[os.environ.get('DB_ENGINE', 'sqlite')]


Don’t forget to add import os!

Runtime Data#

Runtime Data is what makes our application ours. Data, like the user list and site content, is the most precious of all of the information in our application because it cannot be replaced if it’s lost.

What is the runtime data in our application?

Runtime data must be in its own volume.