Which Docker template values are available in docker stack deploy (compose)?

烂漫一生 提交于 2020-01-02 17:33:28

问题


Where can I find out which template values are available in my Docker UCP Swarm cluster?

With template values I mean things like this https://docs.docker.com/engine/reference/commandline/service_create/#create-services-using-templates.

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?

Besides that, I often get errors like for {{.Engine.Labels}}

<.Engine.Labels>: can't evaluate field Engine in type *template.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

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.


回答1:


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
    }

e.g. .Service.ID,.Service.Labels.LabelNameGoesHere, .Task.Name etc.

I was hoping that the Node labels would be exposed and accessible for the templating the docker-compose.yml, but alas not.



来源:https://stackoverflow.com/questions/54251442/which-docker-template-values-are-available-in-docker-stack-deploy-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!