How to Install & Setup Redis for Dokku

How to Install & Setup Redis for Dokku

Redis is a free and open-source in-memory data store which can be used as cache or in same cases even a database. Redis is super simple to install if you manage your applications with your own Dokku PaaS (Platform as a Service).

In today's tutorial I will show you how we can install and setup Redis for Dokku.

1. Install Dokku's Redis Plugin

We start of by installing Dokku's Redis plugin. With this plugin we can easily manage and connect Redis to any application on our server.

sudo dokku plugin:install https://github.com/dokku/dokku-redis.git redis

The plugin requires an installation of dokku 0.12.x+ and docker 1.8.x.

2. Create a Redis Service

When we have installed the redis-dokku plugin we can go ahead and create our first Redis Service.

dokku redis:create service-name

3. Link your Redis Service with your Application

When you have created your Redis Service it is time to link it with your application container. We must do this to make Redis aware to what application to connect to, as you can have multiple application running on a dokku instance.

dokku redis:link service-name app-name

4. Add Redis REDIS_URL to Production Settings

Add the new REDIS_URL to your .env variables in your local development project and modify your production settings accordingly. This will of course vary depending on what application you are building and with what language, framework or tool you are using.

In django for example I use "django-environ" to handle .env and spcify my production CACHES settings as such.

CACHES = {
    'default': env.cache('REDIS_URL')
}

I have barley scratched the surface of what's possible with the dokku-redis plugin in this tutorial, Although this is all you have to do to get Redis up and running with Dokku.

I urge you to further explore the commmands below to get a better understanding of what's possible with this Dokku plugin.

Redis Dokku Commands

redis:app-links                               # list all redis service links for a given app
redis:backup   [--use-iam]   # creates a backup of the redis service to an existing s3 bucket
redis:backup-auth       # sets up authentication for backups on the redis service
redis:backup-deauth                       # removes backup authentication for the redis service
redis:backup-schedule    [--use-iam] # schedules a backup of the redis service
redis:backup-schedule-cat                 # cat the contents of the configured backup cronfile for the service
redis:backup-set-encryption   # sets encryption for all future backups of redis service
redis:backup-unschedule                   # unschedules the backup of the redis service
redis:backup-unset-encryption             # unsets encryption for future backups of the redis service
redis:clone   [--clone-flags...] # create container  then copy data from  into 
redis:connect                             # connect to the service via the redis connection tool
redis:create  [--create-flags...]         # create a redis service
redis:destroy  [-f|--force]               # delete the redis service/data/container if there are no links left
redis:enter                               # enter or run a command in a running redis service container
redis:exists                              # check if the redis service exists
redis:export                              # export a dump of the redis service database
redis:expose                    # expose a redis service on custom port if provided (random port otherwise)
redis:import                              # import a dump into the redis service database
redis:info  [--single-info-flag]          # print the service information
redis:link   [--link-flags...]       # link the redis service to the app
redis:linked                         # check if the redis service is linked to an app
redis:links                               # list all apps linked to the redis service
redis:list                                         # list all redis services
redis:logs  [-t|--tail]                   # print the most recent log(s) for this service
redis:promote                        # promote service  as REDIS_URL in 
redis:restart                             # graceful shutdown and restart of the redis service container
redis:start                               # start a previously stopped redis service
redis:stop                                # stop a running redis service
redis:unexpose                            # unexpose a previously exposed redis service
redis:unlink                         # unlink the redis service from the app
redis:upgrade  [--upgrade-flags...]       # upgrade service  to the specified versions
Freddie Freddie 2 years, 6 months ago 0
Did you enjoy Freddie Freddie's article?
How to Install & Setup Redis for Dokku
Login to Comment
No comments have been posted yet, be the first one to comment.
10 Ways to Manage Environment Variables with Dokku Config Commands
10 Ways to Manage Environment Variables with Dokku Config Commands
Dokku is an awesome open-soure project that makes it really simple to setup and manage your own docker-powered PaaS (Platform-as-a-Service). If you're a solo developer or working in a small team with a low budget, Dokku is godsend. Most applications requires some sort configuration to...
Setup SSL Certificates & Serve your Applications over HTTPS for Free with Dokku & Let's Encrypt
Setup SSL Certificates & Serve your Applications over HTTPS for Free with Dokku & Let's Encrypt
In this tutorial we are going to take a look at how we can setup free SSL certificates for our Dokku powered applications with Let's Encrypt. Let's Encrypt is a non-profit organization that provides TLS (Transport Layer Security) encryption at no charge. Their goal is to make the web ...
How to use Gitlab's CI/CD Pipelines with Dokku to Push your Application to Production
How to use Gitlab's CI/CD Pipelines with Dokku to Push your Application to Production
GitLab is a DevOps lifecycle tool similar to that of GitHub. With GitLab we can host our git-repository and utilize its CI/CD pipeline features to push our development code to production for free. In this tutorial I will show you how you can use GitLab's CI/CD pipelines to push our de...