This guide provides step-by-step instructions to deploy a Flask application on Dokku, set up PostgreSQL and Redis services, and enable Let's Encrypt for SSL.
-
Dokku Installation: Ensure Dokku is installed on your server. You can follow the official Dokku installation guide if it's not already installed.
-
Domain Setup: Make sure your domain is pointed to your server's IP address.
dokku apps:create your-app-name
-
Install the PostgreSQL Plugin (if not already installed):
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
-
Create a PostgreSQL Service:
dokku postgres:create your-app-name-db
-
Link the PostgreSQL Service to Your App:
dokku postgres:link your-app-name-db your-app-name
-
Install the Redis Plugin (if not already installed):
sudo dokku plugin:install https://github.com/dokku/dokku-redis.git redis
-
Create a Redis Service:
dokku redis:create your-app-name-redis
-
Link the Redis Service to Your App:
dokku redis:link your-app-name-redis your-app-name
Set any necessary environment variables, such as SECRET_KEY
, using:
dokku config:set your-app-name SECRET_KEY='your-secret-key'
-
Add Dokku Remote:
git remote add dokku dokku@your-server-ip:your-app-name
-
Push Your Code to Dokku:
git push dokku main
Replace
main
with your branch name if different.
-
Install the Let's Encrypt Plugin (if not already installed):
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
-
Set the Domain for Your App:
dokku domains:set your-app-name your-domain.com
-
Enable Let's Encrypt:
dokku letsencrypt:enable your-app-name
-
Set Up Automatic Renewal:
dokku letsencrypt:cron-job --add
-
Static Files: Ensure your Flask app is configured to serve static files correctly. You might need to adjust your
app.py
to set thestatic_folder
path if not already done. -
Debug Mode: Make sure to set
DEBUG=False
in production for security reasons. -
Database Migrations: If you use Flask-Migrate, run migrations after deployment:
dokku run your-app-name flask db upgrade
By following these steps, you should have your Flask application running on Dokku with PostgreSQL and Redis services, secured with Let's Encrypt SSL.