Search code examples
dockerinfluxdbtelegraf

install influxdb in a docker with non standard port


I am new in dockers and I need some help please. I am trying to install TICK in docker. Influxdb, Kapacitor and Chronograf will be installed in dockers but telegraf will be installed in each machine that will be necessary. Port 8086 in my host is in use, so I will use 8087 for influxdb. Is it posible to configure influxdb dokcer with -p 8087:8086? If so, which port should I configure in conf files? Docker compose file will be:

version: '3'

networks:
    TICK_network:

services:

influxdb:
    image: influxdb
    container_name: influxdb
    networks:
        TICK_network:
    ports:
        - "8087:8086"
        - "8083:8083"
    expose:
        - "8087"
        - "8083"
    hostname: influxdb
    volumes:
        - /var/lib/influxdb:/var/lib/influxdb
        - /etc/influxdb/influxdb.conf:/etc/influxdb/influxdb.conf:ro
    restart: unless-stopped

kapacitor:
    image: kapacitor
    container_name: kapacitor
    networks:
        TICK_network:
    links:
        - influxdb
    ports:
        - "9092:9092"
    expose:
        - "9092"
    hostname: kapacitor
    volumes:
        - /var/lib/kapacitor:/var/lib/kapacitor
        - /etc/kapacitor/kapacitor.conf:/etc/kapacitor/kapacitor.conf:ro
    restart: unless-stopped

chronograf:
    image: chronograf
    container_name: chronograf
    networks:
        TICK_network:
    links:
        - influxdb
        - kapacitor
    ports:
        - "8888:8888"
    expose:
        - "8888"
    hostname: chronograf
    volumes:
        - /var/lib/chronograf:/var/lib/chronograf
    restart: unless-stopped

influxdb.conf is edited to point to port 8087

[http]
  enabled = true
  bind-address = ":8087"
  auth-enabled = true

Kapacitor.conf and telegraf.conf are also pointing to port 8087. But I am receiving following errors:

Telegraf log:

W! [outputs.influxdb] when writing to [http://localhost:8087]: database "telegraf" creation failed: Post http://localhost:8087/query: EOF
E! [outputs.influxdb] when writing to [http://localhost:8087]: Post http://localhost:8087/write?db=tick: EOF
E! [agent] Error writing to outputs.influxdb: could not write any address

kapacitor log:

vl=error msg="encountered error" service=run err="open server: open service *influxdb.Service: failed to link subscription on startup: authorization failed"
run: open server: open service *influxdb.Service: failed to link subscription on startup: authorization failed

Solution

  • What you did is correct if you want to access those services from outside the Docker network, that is from the host access to localhost:8087 for example.

    However, this is not correct in your case. As you are using docker-compose, all the services are in the same network, and therefore, you need to attack the port in which the influx is listening in the Docker network (the right-side port), that is, 8086.

    But, even if you do so, it will still not work. Why? Because you are trying to access localhost from the Telegraf container. You need to configure the access to influx as influxdb:8086, not as localhost:8087. influxdb here is the name of the container, if for example you name it ailb90, then it would be ailb90:8086