Preparing Your Application for Deployment

1. Add a file named Procfile to the root of your application and specify the startup command.

Django example:

web: gunicorn myproject.wsgi --log-file -

Flask example:

web: gunicorn myproject.wsgi

2. Install Gunicorn and freeze requirements:

pip install gunicorn
pip freeze > requirements.txt

Note: any other application dependencies should also be listed in requirements.txt before you freeze it.

3. Specify a Python Runtime (optional)

Newly created Python applications default to the Python 2.7 runtime (to see the current default version, refer to the Python buildpack). If you need to specify a different vesion, create a file named runtime.txt and add it to the root of your git project, and list the python version. Supported versions:

Supported Python Versions

python-2.7.15

python-3.6.6

python-3.7.0

Unsupported Python Versions

Unsupported runtimes can also be specified. However, we only endorse and support the use of the supported versions listed above, since they represent the most secure versions.

4. Configure environment variables

In Dokku, sensitive credentials are stored in environment configuration variables. This includes database connection information (DATABASE_URL), which is traditionally hardcoded in Django and other Python applications. Environment variables are created using the Dokku command line interface:

dokku config:set my-app-name SOME_KEY=SOME_VALUE

Then your application code should be adjusted to retrieve the value from the environment. For example, a Flask application:

app.config.from_envvar('SOME_KEY')

For Django apps, the dj-database-url package parses the DATABASE_URL environment variable and converts it to Django's desired configuration format, automatically.

Important: the DATABASE_URL environment variable should specify the SSL option, so that communication between your application and database is encrypted. Examples are shown in the Dokku Getting Started Guide, under "Database Configuration." Note that MySQL connections require additional configuration steps in your Python application.

Deploy your App

Using Docker Natively

Frequently Asked Questions

How do I switch to a different Python buildpack?

Periodically, we upgrade Dokku to the latest stable version, which also includes updated references to various buildpacks. However, if you would like to use a newer buildpack version that is not yet present on your server, or a different one altogether, you can run the following command: