10 Ways to Manage Environment Variables with Dokku Config Commands

DevOps DevOps
Dokku Dokku
.env .env
Environment Variable Environment Variable
PaaS PaaS

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

Did You Enjoy the Tutorial?

Consider sending some love to Freddie the creator.

Comments (0)

You need to be logged in to comment..

Topics Mentioned in this Tutorial

DevOps
6
0
24
DevOps stands for Development Operations and is a set of practices used to improve software development and information-technology operations. Part of the DevOps responsibility is to setup servers, integrate continuous integration and continuous deployment (CI/CD) to maintain and improve the development life cycle....
Dokku
7
0
0
With Dokku web developers can build their own PaaS (Platform-as-a-Service) with help of Docker and open sourced Heroku build packs. Dokku Installs on any hardware and drastically lowers your cost as Dokku is both free and open source. The dokku setup process is extremly simple and only takes a matter of minutes to complete. Once Dokku is installed and your PaaS is ready for use you can push your local development project using Git. Which builds your applicaion using Heroku buildpacks that runs in isolated Docker containers. As a result, you can run your own PaaS on the cloud provider of your c...
.env
1
0
0
PaaS
4
0
0
PaaS stands for Platform-as-a-Service is a complete development and deployment environment in the cloud. With a PaaS you developers can deliver anything form simple cloud app to sophisticated enterprise applications. A PaaS toolset includes development tools, database management and business analytics. It also includes all of the features included in an IaaS (Infrastructure-as-a-Service) servers and storage, networking security and data center.   ...