Browse code

Add documentation about templating support on…

… services creation/update.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2016/11/18 23:28:01
Showing 2 changed files
... ...
@@ -474,6 +474,44 @@ accessible at the target port on every node regardless if there is a task for
474 474
 the service running on the node. For more information refer to
475 475
 [Use swarm mode routing mesh](https://docs.docker.com/engine/swarm/ingress/).
476 476
 
477
+### Create services using templates
478
+
479
+You can use templates for some flags of `service create`, using the syntax
480
+provided by the Go's [text/template](http://golange.org/pkg/text/template/) package.
481
+
482
+The supported flags are the following :
483
+
484
+- `--hostname`
485
+- `--mount`
486
+- `--env`
487
+
488
+Valid placeholders for the Go template are listed below:
489
+
490
+Placeholder       | Description
491
+----------------- | --------------------------------------------
492
+`.Service.ID`     | Service ID
493
+`.Service.Name`   | Service name
494
+`.Service.Labels` | Service labels
495
+`.Node.ID`        | Node ID
496
+`.Task.ID`        | Task ID
497
+`.Task.Name`      | Task name
498
+`.Task.Slot`      | Task slot
499
+
500
+#### Template example
501
+
502
+In this example, we are going to set the template of the created containers based on the
503
+service's name and the node's ID where it sits.
504
+
505
+```bash
506
+$ docker service create --name hosttempl --hostname={% raw %}"{{.Node.ID}}-{{.Service.Name}}"{% endraw %} busybox top
507
+va8ew30grofhjoychbr6iot8c
508
+$ docker service ps va8ew30grofhjoychbr6iot8c
509
+NAME                      IMAGE                                                                                   NODE          DESIRED STATE  CURRENT STATE               ERROR  PORTS
510
+hosttempl.1.wo41w8hg8qan  busybox:latest@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912  2e7a8a9c4da2  Running        Running about a minute ago
511
+$ docker inspect --format={% raw %}"{{.Config.Hostname}}"{% endraw %} hosttempl.1.wo41w8hg8qanxwjwsg4kxpprj
512
+x3ti0erg11rjpg64m75kej2mz-hosttempl
513
+```
514
+
477 515
 ## Related information
478 516
 
479 517
 * [service inspect](service_inspect.md)
... ...
@@ -164,6 +164,11 @@ $ docker service update \
164 164
     myservice
165 165
 ```
166 166
 
167
+### Update services using templates
168
+
169
+Some flags of `service update` support the use of templating.
170
+See [`service create`](./service_create.md#templating) for the reference.
171
+
167 172
 ## Related information
168 173
 
169 174
 * [service create](service_create.md)