Subscription connection issue when Kapacitor docker set with custom hostname

How to replicate:

Using the latest 1.3.1 image version

- name: Create Kapacitor Container
  become: yes
    name: kapacitor
    image: "{{ image_name }}"
    hostname: "kapacitor-dev"  <===
      - name: influxdata
    restart_policy: always
    state: started
    published_ports: "9092:9092"
    exposed_ports: "9092/tcp"
    log_driver: journald
      - /etc/kapacitor/kapacitor.conf:/etc/kapacitor/kapacitor.conf:ro
      - /kapacitor:/var/lib/kapacitor
    - wait for port status

Error message in InfluxDB container:

[I] 2017-07-28T17:10:25Z Post http://kapacitor-dev:9092/write?consistency=&db=investopedia&precision=ns&rp=default: dial tcp: lookup kapacitor-dev on no such host service=subscriber

When I remove the “hostname” in my ansible config and deploy, subscription works fine, no connection refuse error.

All containers (telegraf, influxdb, kapacitor) are on the same host. Telegraf and Influxdb communicate fine using the same “networks: influxdata” and custom hostname.

I don’t think that docker networks use the hostname as the DNS to connect to another node. So referencing kapacitor in the influxdb container would probably work, but I don’t think kapacitor-dev would. You likely want to set the hostname and the name of the container to be the same thing.