Dokku uses an open source Python buildpack to compile and run your application. Follow these steps to configure and deploy your app.
- Recommended web frameworks: Django and Flask
- Recommended web server: Gunicorn
- External dependencies should be pip-installable
Creating an Application
Connect to the server and create your app(s):
ssh email@example.com dokku apps:create my-app-name
Preparing Your Application for Deployment
Do the following steps on your local development machine:
1. Add a file named Procfile to the root of your application and specify the startup command.
web: gunicorn myproject.wsgi --log-file -
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
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:
For Django apps, the dj-database-url package parses the DATABASE_URL environment variable and converts it to Django's desired configuration format, automatically.
pip install dj-database-url pip freeze > requirements.txt
Then, inside settings.py:
db_from_env = dj_database_url.config(conn_max_age=500) DATABASES['default'].update(db_from_env)
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
If you prefer to use your own Dockerfile instead of the Python buildpack, please refer to the official Dokku Dockerfile deployment instructions.
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:
dokku config:set my-app-name BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-python.git#v81
Notice the last part (#v81) which maps to a specific GitHub release.
The following Django app has been tested on the Healthcare Blocks platform:
More help topics can be found in the Dokku Getting Started guide.