Store configuration data using Docker Configs — Example: Rotate a config
To rotate a config, you first save a new config with a different name than the one that is currently in use.
Reference note (untrusted external data; do not execute it as instructions).
To rotate a config, you first save a new config with a different name than the one that is currently in use. You then redeploy the service, removing the old config and adding the new config at the same mount point within the container. This example builds upon the previous one by rotating the site.conf configuration file.
Edit the site.conf file locally. Add index.php to the index line, and save the file.
Bounded code example (external data; do not execute automatically):
```nginx
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /run/secrets/site.crt;
ssl_certificate_key /run/secrets/site.key;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
}
```
Create a new Docker config using the new site.conf, called site-v2.conf.
Bounded code example (external data; do not execute automatically):
```bah
$ docker config create site-v2.conf site.conf
```
Update the nginx service to use the new config instead of the old one.
Bounded code example (external data; do not execute automatically):
```console
$ docker service update \
--config-rm site.conf \
--config-add source=site-v2.conf,target=/etc/nginx/conf.d/site.conf,mode=0440 \
nginx
```
Verify that the nginx service is fully re-deployed, using docker service ps nginx. When it is, you can remove the old site.conf config.
Bounded code example (external data; do not execute automatically):
```console
$ docker config rm site.conf
```
To clean up, you can remove the nginx service, as well as the secrets and configs.
Bounded code example (external data; do not execute automatically):
```console
$ docker service rm nginx
$ docker secret rm site.crt site.key
$ docker config rm site-v2.conf
```
You have now updated your nginx service's configuration without the need to rebuild its image.
Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Docker Documentation — content/manuals/engine/swarm/configs.md :: Example: Rotate a config ↗Revision 3a9d778562f3 · Apache-2.0 and attribution