Templates

You can generate configuration for your service with jinga2 template.

Here is an example for an hypothetical ssh config file:

host server:
    hostname {{links.ssh.ip}}
    port {{links.ssh.port}}

Templates will be replaced with ip address and port of the identified link. All links can be accessed from links.all, this is a tuple of links you can iterate on it.

{% for link in links.all %}
host {{link.names[0]}}
    hostname {{link.ip}}
    port {{links.port}}
{% endfor %}

If you change the option single to false in the entrypoint-config.yml, the identified link ssh will become a tuple of links. You must iterate on it in the jinja template.

{% for link in links.ssh %}
host {{link.names[0]}}
    hostname {{link.ip}}
    port {{links.port}}
{% endfor %}

Accessing environment in template.

{% if 'SSHKEY in env' %}
{{env['SSHKEY']}}
{% endfor %}

Accessible objects

You have 4 available objects in your templates.

  • config
  • links
  • containers
  • environ

config

Config reflect the config file. You can retrieve any setup in this object.

(see config.py)

containers

Not supported when using docker network or docker-compose v2.

containers handles a tuple of container object.

container handles the following attributes: - ip - container ip - environ - container environment - names - List of containers names - Names are sorted by length, but container ID will be the last element. - id - Hexadecimal container ID (if available, empty string else) - links - Tuple of link objects related to this container

environ

environ is the environment of the container (os.environ).

env is an alias to environ.

yaml and json

yaml and json objects are respectively an import of PyYAML <http://pyyaml.org/> and `json <https://docs.python.org/2/library/json.html> modules.

They are useful to load and dump serialized data from environment.