- [Instructor] A very new feature
in the Docker engine with Docker swarm is the ability
to deploy Docker services using templates.
So, what are templates?
Well, templates allow you to embed information
from the Docker host operating system
where you're running Docker into the services
and thus into the containers
that you're deploying inside those services.
The only valid options that you can embed
at this point are the hostname,
so you can take the hostname, for example,
from the Docker host and then you can embed
that inside the containers that are deployed in the service.
Another example would be taking the name
of the service itself and you can embed
that inside the container.
So, you have a few different things you can embed.
The syntax for what you want to embed in the template
for the service is based on the Go text template format
and I'll show you a link to that here in just a moment.
The syntax to deploy a service in Docker using a template is
to use the Docker service create command
and then, for example, we can do --hostname
and then this is where you would embed the hostname
of the Docker host where this service is being deployed.
And then, after that, you would continue the command
with the image.
Let's check out the documentation
because they have extensive information
on how to define these template files.
Here in the Docker service create command syntax,
they show you all the valid placeholders
for the Go template that you can configure
as well as links to the Go text template package.
They also have template examples
that you can run on your own host.