Docker堆栈部署(撰写)中可以使用哪些Docker模板值? [英] Which Docker template values are available in docker stack deploy (compose)?
问题描述
在哪里可以找到我的Docker UCP Swarm集群中可用的模板值?
Where can I find out which template values are available in my Docker UCP Swarm cluster?
使用 template 值,我的意思是这样的 https://docs.docker.com/engine / reference / commandline / service_create /#create-services-using-templates 。
With template values I mean things like this https://docs.docker.com/engine/reference/commandline/service_create/#create-services-using-templates.
我感觉到我正在遍历的树看起来有点像 docker inspect
输出,但输出较小。哪个键?以及我可以使用哪些表达式?
I get the feeling that the tree I'm traversing looks a bit like docker inspect
output, but a smaller set of it. Which keys? and which expressions can I use?
除此之外,我经常会遇到诸如 {{。Engine.Labels}} $ c $之类的错误。 c>
Besides that, I often get errors like for {{.Engine.Labels}}
<.Engine.Labels>: can't evaluate field Engine in type *template.Context
因此,似乎存储树的上下文是 Context。据我所知,这不是码头工人的概念。
So, it seems the context in which the tree is stored is 'Context'. Which is not a docker concept as far as I know.
我尝试使用此方法的示例:
An example of how I'm trying to use this:
version: "3.7"
services:
bar:
image: foo/bar:latest
environment:
- hostname={{.Node.Hostname}}
deploy:
replicas: 2
在 docker inspect
中还有一个-format
标志,您可以在其中使用相同的go-template语法,但不是可在docker堆栈设置中使用的树。
In docker inspect
there is also a --format
flag where you can use the same go-template syntax, but it is not the tree that can be used in the docker stack setup.
推荐答案
I 相信,其中的 context.go swarmkit仓库负责。
I believe that context.go in the swarmkit repo is responsible.
这意味着您具有以下条件:
This means you have the following:
Service struct {
ID string
Name string
Labels map[string]string
}
Node struct {
ID string
Hostname string
Platform Platform
}
Task struct {
ID string
Name string
Slot string
}
例如 .Service.ID
, .Service.Labels.LabelNameGoesHere
, .Task.Name
等。
我希望可以为docker-compose.yml模板暴露和访问Node标签,但是可惜没有。
I was hoping that the Node labels would be exposed and accessible for the templating the docker-compose.yml, but alas not.
这篇关于Docker堆栈部署(撰写)中可以使用哪些Docker模板值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!