Sfoglia il codice sorgente

Add documentation about templating support on…

… services creation/update.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 4571ad05dba48eda9d138c4db20bd2a63022ff63)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
Vincent Demeester 8 anni fa
parent
commit
2fb6810841

+ 38 - 0
docs/reference/commandline/service_create.md

@@ -474,6 +474,44 @@ accessible at the target port on every node regardless if there is a task for
 the service running on the node. For more information refer to
 the service running on the node. For more information refer to
 [Use swarm mode routing mesh](https://docs.docker.com/engine/swarm/ingress/).
 [Use swarm mode routing mesh](https://docs.docker.com/engine/swarm/ingress/).
 
 
+### Create services using templates
+
+You can use templates for some flags of `service create`, using the syntax
+provided by the Go's [text/template](http://golange.org/pkg/text/template/) package.
+
+The supported flags are the following :
+
+- `--hostname`
+- `--mount`
+- `--env`
+
+Valid placeholders for the Go template are listed below:
+
+Placeholder       | Description
+----------------- | --------------------------------------------
+`.Service.ID`     | Service ID
+`.Service.Name`   | Service name
+`.Service.Labels` | Service labels
+`.Node.ID`        | Node ID
+`.Task.ID`        | Task ID
+`.Task.Name`      | Task name
+`.Task.Slot`      | Task slot
+
+#### Template example
+
+In this example, we are going to set the template of the created containers based on the
+service's name and the node's ID where it sits.
+
+```bash
+$ docker service create --name hosttempl --hostname={% raw %}"{{.Node.ID}}-{{.Service.Name}}"{% endraw %} busybox top
+va8ew30grofhjoychbr6iot8c
+$ docker service ps va8ew30grofhjoychbr6iot8c
+NAME                      IMAGE                                                                                   NODE          DESIRED STATE  CURRENT STATE               ERROR  PORTS
+hosttempl.1.wo41w8hg8qan  busybox:latest@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912  2e7a8a9c4da2  Running        Running about a minute ago
+$ docker inspect --format={% raw %}"{{.Config.Hostname}}"{% endraw %} hosttempl.1.wo41w8hg8qanxwjwsg4kxpprj
+x3ti0erg11rjpg64m75kej2mz-hosttempl
+```
+
 ## Related information
 ## Related information
 
 
 * [service inspect](service_inspect.md)
 * [service inspect](service_inspect.md)

+ 5 - 0
docs/reference/commandline/service_update.md

@@ -164,6 +164,11 @@ $ docker service update \
     myservice
     myservice
 ```
 ```
 
 
+### Update services using templates
+
+Some flags of `service update` support the use of templating.
+See [`service create`](./service_create.md#templating) for the reference.
+
 ## Related information
 ## Related information
 
 
 * [service create](service_create.md)
 * [service create](service_create.md)