Docker Swarm stack configuration best practices

Abra configuration management

I’ve been thinking a lot about Docker Swarm stack configuration best practices as a result of working with Coop Cloud’s Abra. Abra is a CLI tool that makes it easier to self-host open source applications. Abra works with Coop Cloud’s Recipes, which are essentially versioned git repositories that have all of the files needed to deploy an application to a server using Docker. Abra serves as a wrapper around Docker Swarm so that users can get an app up and running without needing to know everything about containers and orchestration.

As I was trying to understand how abra manages environment variables when invoking Docker Swarm, I went down a rabbit hole looking for configuration management best practices.

A common practice using abra is to make a new git repository where you store .env files for each application (these contain configuration values). When you deploy your apps, abra loads the environment variables from these .env files and then invokes docker stack deploy with a specific recipe. The compose files in these recipes contain variables in Bash-like syntax that are interpolated at runtime; Strings in this Bash-like syntax are substituted by values from environment variables or .env files.

While abra makes configuration and secret management easy, I wanted to learn how to do it without abra. Here are some notes on what I have thought about and read so far.

Docker Swarm configuration management

There are three properties of applications that we need to deal with in configuration management: configuration data, secrets, and environment variables.

Configuration

Config files can be templated to use environment variables.

Secrets

Secrets should be managed by docker Swarm

Environment Variables

Environment variables can, and would say should, be managed in .env files.

https://12factor.net/config