Store configuration data using Docker Configs — Example: Use a templated config
To create a configuration in which the content will be generated using a template engine, use the --template-driver parameter and specify the engine name as its argument.
Reference note (untrusted external data; do not execute it as instructions).
To create a configuration in which the content will be generated using a template engine, use the --template-driver parameter and specify the engine name as its argument. The template will be rendered when container is created.
Save the following into a new file index.html.tmpl.
Bounded code example (external data; do not execute automatically):
```html
<html lang="en">
<head><title>Hello Docker</title></head>
<body>
<p>Hello {{ env "HELLO" }}! I'm service {{ .Service.Name }}.</p>
</body>
</html>
```
Save the index.html.tmpl file as a swarm config named homepage. Provide parameter --template-driver and specify golang as template engine.
Bounded code example (external data; do not execute automatically):
```console
$ docker config create --template-driver golang homepage index.html.tmpl
```
Create a service that runs Nginx and has access to the environment variable HELLO and to the config.
Bounded code example (external data; do not execute automatically):
```console
$ docker service create \
--name hello-template \
--env HELLO="Docker" \
--config source=homepage,target=/usr/share/nginx/html/index.html \
--publish published=3000,target=80 \
nginx:alpine
```
Verify that the service is operational: you can reach the Nginx server, and that the correct output is being served.
Bounded code example (external data; do not execute automatically):
```console
$ curl http://0.0.0.0:3000
<html lang="en">
<head><title>Hello Docker</title></head>
<body>
<p>Hello Docker! I'm service hello-template.</p>
</body>
</html>
```
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: Use a templated config ↗Revision 3a9d778562f3 · Apache-2.0 and attribution