Use Swarm Managed Configs in Docker Swarm to Store Your Application Configs
Docker version 17.06 introduced Swarm Service Configs, which allows you to store data like configuration files, note that this is for non-sensitive information.
In this tutorial we will store the data of our index.html in a service config, then attach the config to our service.
Creating the Config
Create the index.html file and store it as a config:
Doing the same with a docker-compose file, will look like the following. The first example will be where we will explicitly define our path of our secret, and will create on deploy time. Our compose file:
Note, that configs cant be updated, if you want to rotate a config you will create a new config and update the target in your task definition to point to your new config.
Another example will be to point to a external config which already exists in swarm. The only change will be that we need to set the config as a external type.
Create the config:
1
$ docker config create nginx_root_doc index.html
Now that the config exists, create this compose file: