Document .Node.Hostname templating

Update placeholders table and add example code
Follow up to moby/moby#34686

Signed-off-by: Carlo Mion <mion00@gmail.com>
This commit is contained in:
Carlo Mion 2017-09-15 10:18:26 +02:00
parent 7b77ab5c60
commit 21825b6842
1 changed files with 7 additions and 3 deletions

View File

@ -833,6 +833,10 @@ Valid placeholders for the Go template are listed below:
<td><tt>.Node.ID</tt></td> <td><tt>.Node.ID</tt></td>
<td>Node ID</td> <td>Node ID</td>
</tr> </tr>
<tr>
<td><tt>.Node.Hostname</tt></td>
<td>Node Hostname</td>
</tr>
<tr> <tr>
<td><tt>.Task.ID</tt></td> <td><tt>.Task.ID</tt></td>
<td>Task ID</td> <td>Task ID</td>
@ -851,11 +855,11 @@ Valid placeholders for the Go template are listed below:
#### Template example #### Template example
In this example, we are going to set the template of the created containers based on the 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. service's name, the node's ID and hostname where it sits.
```bash ```bash
$ docker service create --name hosttempl \ $ docker service create --name hosttempl \
--hostname="{{.Node.ID}}-{{.Service.Name}}"\ --hostname="{{.Node.Hostname}}-{{.Node.ID}}-{{.Service.Name}}"\
busybox top busybox top
va8ew30grofhjoychbr6iot8c va8ew30grofhjoychbr6iot8c
@ -865,7 +869,7 @@ $ docker service ps va8ew30grofhjoychbr6iot8c
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
wo41w8hg8qan hosttempl.1 busybox:latest@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912 2e7a8a9c4da2 Running Running about a minute ago wo41w8hg8qan hosttempl.1 busybox:latest@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912 2e7a8a9c4da2 Running Running about a minute ago
$ docker inspect --format="{{.Config.Hostname}}" hosttempl.1.wo41w8hg8qanxwjwsg4kxpprj $ docker inspect --format="{{.Config.Hostname}}" 2e7a8a9c4da2-wo41w8hg8qanxwjwsg4kxpprj-hosttempl
x3ti0erg11rjpg64m75kej2mz-hosttempl x3ti0erg11rjpg64m75kej2mz-hosttempl
``` ```