Docker-compose example

Hello, I’m trying to set up a simple telegraf and influxdb instance in a docker network that will capture the default example of system data (ultimately I’d like to capture MQTT). I’ve tried following the official tutorial but I’m a little confused. Running InfluxDB 2.0 and Telegraf Using Docker | InfluxData

Do we need to create docker influxdb instances first to create a config file and save that somewhere before we can use the docker-compose file to work - its a little unclear? I’ve tried to run the docker-compose substituting my username and home directory but leaving all the ./ references the same.

When I run docker-compose up I get the following error:
ERROR: Couldn’t find env file: /home/svl/influxv2.env

How do I create this file - is this a config file I need to build using the initial containers at the beginning of the tutorial?

From what I understand the docker-compose should be a new instance and will define the username, password etc using the CLI? these are then stored as docker environmental variables that will be shared and available to both influxdb and telegraf?

Have I miss understood this tutorial and how it works - also can the system example be added so we can see some data being populated in the running example?

Many thanks!

this is my docker-compose file based on the example - do I need to change the environmental variables or can I use these as they are for testing purposes?

version: '3'
services:
  influxdb:
    image: influxdb:latest
    volumes:
      # Mount for influxdb data directory and configuration
      - /home/svl/influxdb2:/var/lib/influxdb2:rw
    ports:
      - "8086:8086"
  # Use the influx cli to set up an influxdb instance. 
  influxdb_cli:
    links:
      - influxdb
    image: influxdb:latest
    volumes:
      # Mount for influxdb data directory and configuration
      - /home/svl/influxdb2:/var/lib/influxdb2:rw
      - ./ssl/influxdb-selfsigned.crt:/etc/ssl/influxdb-selfsigned.crt:rw
      - ./ssl/influxdb-selfsigned.key:/etc/ssl/influxdb-selfsigned.key:rw
    environment: 
       # Use these same configurations parameters in your telegraf configuration, mytelegraf.conf.
      - DOCKER_INFLUXDB_INIT_MODE=setup
      - DOCKER_INFLUXDB_INIT_USERNAME=myusername
      - DOCKER_INFLUXDB_INIT_PASSWORD=passwordpasswordpassword
      - DOCKER_INFLUXDB_INIT_ORG=myorg
      - DOCKER_INFLUXDB_INIT_BUCKET=mybucket
      - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=mytoken
      - INFLUXD_TLS_CERT=/etc/ssl/influxdb-selfsigned.crt
      - INFLUXD_TLS_KEY=/etc/ssl/influxdb-selfsigned.key
    entrypoint: ["./entrypoint.sh"]
    restart: on-failure:10
    depends_on:
      - influxdb
  telegraf:
    image: telegraf
    links:
      - influxdb
    volumes:
      # Mount for telegraf config
      - ./telegraf/mytelegraf.conf:/etc/telegraf/telegraf.conf
    env_file:
      - ./influxv2.env
    environment: 
      - DOCKER_INFLUXDB_INIT_ORG=myorg
      - DOCKER_INFLUXDB_INIT_BUCKET=mybucket
      - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=mytoken
    depends_on:
      - influxdb_cli
volumes:
  influxdb2:

Should a docker-compose file just work out of the box like this?

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

This is perfect - thank you!!