Generating a unique hostname for Docker Swarm service containers

You can use Go templates for the hostname. For example, you could do --hostname="frontend-{{.Node.Hostname}}-{{.Task.ID}}" to append the swarm node’s host name and the service task’s ID.

See Create services using templates.

2 Likes