mirror of https://github.com/docker/docs.git
Add example for templated config
Signed-off-by: Paweł Szczekutowicz <pszczekutowicz@gmail.com>
This commit is contained in:
parent
7caf4095a4
commit
fc0327569c
|
@ -278,6 +278,56 @@ This example assumes that you have PowerShell installed.
|
|||
docker config rm homepage
|
||||
```
|
||||
|
||||
### 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. The template will be rendered when container is created.
|
||||
|
||||
1. Save the following into a new file `index.html.tmpl`.
|
||||
|
||||
```html
|
||||
<html>
|
||||
<head><title>Hello Docker</title></head>
|
||||
<body>
|
||||
<p>Hello {% raw %}{{ env "HELLO" }}{% endraw %}! I'm service {% raw %}{{ .Service.Name }}{% endraw %}.</p>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
2. Save the `index.html.tmpl` file as a swarm config named `homepage`. Provide
|
||||
parameter `--template-driver` and specify `golang` as template engine.
|
||||
|
||||
```bash
|
||||
$ docker config create --template-driver golang homepage index.html.tmpl
|
||||
```
|
||||
|
||||
3. Create a service that runs Nginx and has access to the environment variable
|
||||
HELLO and to the config.
|
||||
|
||||
```bash
|
||||
$ 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
|
||||
```
|
||||
|
||||
4. Verify that the service is operational: you can reach the Nginx server, and
|
||||
that the correct output is being served.
|
||||
|
||||
```bash
|
||||
$ curl http://0.0.0.0:3000
|
||||
|
||||
<html>
|
||||
<head><title>Hello Docker</title></head>
|
||||
<body>
|
||||
<p>Hello Docker! I'm service hello-template.</p>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
### Advanced example: Use configs with a Nginx service
|
||||
|
||||
This example is divided into two parts.
|
||||
|
|
Loading…
Reference in New Issue