Docker-compose example

Hi @om327 ,

I setup a telegraf/influxdb instance in docker last week with no prior experience. I used the tutorial you mentioned above and also this companion YouTube video which closely follows the tutorial.

In my case, I setup Telegraf standalone and verified it was collecting data and reporting it to stdout. Then I expanded the compose file adding InfluxDB. I decided to hard-code the bucket name, org and token directly into telegraf.conf instead of using the .env and entrypoint.sh stuff in the tutorial. This was partly to keep it simple and partly to discover a minimalist configuration that actually works. So I didn’t include Influx CLI in the compose file and just launched the InFluxDB container and browsed to its UI. That’s where I created an admin account, password, etc and once inside InfluxDB I looked up the auto-generated admin token and pasted that into telegraf.conf. My compose file is as follows:

services:
  influxdb:
    image: influxdb:latest
    container_name: influxdb2
    volumes:
      - /mnt/influxdb/data:/var/lib/influxdb2:rw
#    env_file:
#      - .env
#    entrypoint: ["./entrypoint.sh"]
    ports:
      - 8086:8086
    restart: unless-stopped

  telegraf:
    image: telegraf:latest
    container_name: telegraf
#    links:
#      - influxdb
    volumes:
      #  Sync timezone with host
      - /etc/localtime:/etc/localtime:ro
      #  Map Telegraf configuration file
      - /mnt/influxdb/telegraf.conf:/etc/telegraf/telegraf.conf:ro
      #  Map /tmp to permanent storage  (this includes /tmp/metrics.out)
      - /mnt/influxdb:/tmp:rw
    restart: unless-stopped
    depends_on:
      - influxdb

2 Likes