Metricbeat supports templates for modules:

["source","yaml",subs="attributes"]
-------------------------------------------------------------------------------------
metricbeat.autodiscover:
  providers:
    - type: docker
      labels.dedot: true
      templates:
        - condition:
            contains:
              docker.container.image: redis
          config:
            - module: redis
              metricsets: ["info", "keyspace"]
              hosts: "${data.host}:6379"
-------------------------------------------------------------------------------------

This configuration launches a `redis` module for all containers running an image with `redis` in the name.
`labels.dedot` defaults to be `true` for docker autodiscover, which means dots in docker labels are replaced with '_' by default.

Also Metricbeat autodiscover supports leveraging <<keystore>> in order to retrieve sensitive data like passwords.
Here is an example of how a configuration using keystore would look like:

["source","yaml",subs="attributes"]
-------------------------------------------------------------------------------------
metricbeat.autodiscover:
  providers:
    - type: docker
      labels.dedot: true
      templates:
        - condition:
            contains:
              docker.container.image: redis
          config:
            - module: redis
              metricsets: ["info", "keyspace"]
              hosts: "${data.host}:6379"
              password: "${REDIS_PASSWORD}"
-------------------------------------------------------------------------------------

where `REDIS_PASSWORD` is a key stored in local keystore of Metricbeat.
