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 function and run securely. This can be anything from API keys, secret keys or other settings. The industry standard is to use a .env file with environment variables to handle these settings securely. We do not want to have these keys visible to praying eyes in our Git repository or else where sensitive information could be exposed.

Dokku has multiple commands dedicated to managing environment variables. Today we are going to take a look at how we can set and manage our environment (.env) variables for your Dokku instance.

Dokku Configuration Commands

config (|--global)                                                               Pretty-print an app or global environment
config:bundle (|--global) [--merged]                                             Bundle environment into tarfile
config:clear (|--global)                                                         Clears environment variables
config:export (|--global) [--envfile]                                            Export a global or app environment
config:get (|--global) KEY                                                       Display a global or app-specific config value
config:keys (|--global) [--merged]                                               Show keys set in environment
config:set [--encoded] [--no-restart] (|--global) KEY1=VALUE1 [KEY2=VALUE2 ...]  Set one or more config vars
config:unset [--no-restart] (|--global) KEY1 [KEY2 ...]                          Unset one or more config vars

View current environment variables for a specific application

To get an overview what enviroment variables is set for a specific application we can simply run an empty config command. This is useful when you need to know if an enviroment variable that you require is set or not.

dokku config appname

Set an environment variable for a specific application

The config:set command is possibly the most commonly used command. You can set an environment variable for a specific application as following.

dokku config:set appname VAR=Value

Set a global environment variable

We can also set global enviroment variables with the --global flag. This is handy if you need to set a environment variable that works for all containers.

dokku config:set --global VAR=Value

Set multiple environment variables at the same time

Sometimes you application requires a ton of configuration where a hand full of variables needs to be set. To save some time you can set multiple environment variables at the same time.

dokku config:set appname VAR1=Value1 VAR2=Value2 VAR3=Value3

Set environment variable without server restart

Everytime you set a new variable your server is restarted. This is not always the wanted outcome, you can surpass the automatic restart by utilizing the --no-restart flag

dokku config:set --no-restart appname VAR=Value

Set environment variables with spaces & special charaters

Sometimes your environment values need to contain spaces, you can achive this by double quoting your string and backslash-escape the spaces. The double quotation can also be used if your value contains special charaters.

dokku config:set appname VAR="Value\ With\ Spaces"

Set Base64 encoded environment variables

In rare ocations you need to Base64 encode a value. Dokku can read Base64 encoded values which can be achived by utilizing the --encode flag.

dokku config:set --encoded appname VAR="$(base64 ~/.ssh/id_rsa)"

Delete a specific environment variable for a specific application

If you want to get rid of a specific environment varaible for a specific app you can use the config:unset followed by the appname and variable.

dokku config:unset appname VAR1

Delete all environment variable for a specific application

To delete all your environment variables for a specific application we can use the config:clear command.

dokku config:clear appname

Clear all global enironment variables

To delete all global environment variables we can use the --global flag.

dokku config:clear --global
Freddie Freddie 2 years, 6 months ago 0
Did you enjoy Freddie Freddie's article?
10 Ways to Manage Environment Variables with Dokku Config Commands
Login to Comment
No comments have been posted yet, be the first one to comment.
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 a...
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...