Influx v2 - telegraf configuration on docker

I’m new to this so I’m sorry if this is a trivial question.

I’m having issues in the first configuration of influxDB v2.0 with telegraf on two separate container.
The containers are linked to the same network, the whole set-up is specified in a docker-compose file.

I go through the credential set-up in the browser and in -> Data -> Telegraf I create a new configuration to get the telegraf token. Once I have the token I do

export INFLUX_TOKEN=“token”

in the telegraf container bash and I try

telegraf --config “link API”

but i get the following error

[telegraf] Error running agent: Error loading config file http://localhost:8086/api/v2/telegrafs/06e759e9a4784000: Get “http://localhost:8086/api/v2/telegrafs/06e759e9a4784000”: dial tcp connect: connection refused

What is wrong here? I tried to go through the documentation but I really don’t understand, any help is appreciated.

Guys I figured it out!

I was sending data to influxDB at localhost:8086 but influx is running on a docker container, therefore I have to use container_ip:8086, in my case

Hello @arma96,
Here’s a docker-compose for telegraf and influxdb v2 as well:

version: '3'
      # Mount for influxdb data directory and configuration
      - influxdbv2:/.influxdbv2
      - "8086:8086"
# Use the influx cli to set up an influxdb instance. 
      - influxdb
# Use these same configurations parameters in your telegraf configuration, mytelegraf.conf.
    entrypoint: influx setup --bucket mybucket -t mytoken -o myorg --username=myusername --password=passwordpasswordpassword --host=http://influxdb:8086 -f
      # Wait for the influxd service in the influxdb container has fully bootstrapped before trying to setup an influxdb instance with the influxdb_cli service. 
    restart: on-failure:10
      - influxdb
    image: telegraf
      - influxdb
      # Mount for telegraf config
      - ./telegraf/mytelegraf.conf:/etc/telegraf/telegraf.conf
      - influxdb_cli

Where the output portion of your telegraf config should look like:

# Output Configuration for telegraf agent
  ## Point to your influxdb container
 urls = ["http://influxdb:8086"]
  ## Token for authentication.
  token = "mytoken"
  ## Organization is the name of the organization you wish to write to; must exist.
  organization = "myorg"
  ## Destination bucket to write into.
  bucket = "mybucket"

Thanks, this informations are really useful!

Hi there,
First post and extremely new in influxdb!
I understand the contents of the docker-compose file but not the intents!
I am an old dinosaur used to work in old languages in old Unixes.
Could you please help me in this situation?

  • why should I need 2 influxdb instances (influxdb and influxdb_cli)?
  • being so why do I need to run ‘setup’ in every run? Any init script?

As I said as being new to influxdb I don’t know if those questions are pertinent!


Now when trying to use your files!

I did minor modifications mainly in the “volumes” section!

# Mount for influxdb data directory and configuration
- ./influxdbv2:/.influxdbv2
# Mount for telegraf config
- ./mytelegraf.conf:/etc/telegraf/telegraf.conf

now i had the dir mounted on the actual folder also linked the conf file

osx% ls -> docker-compose.yml influxdbv2/ mytelegraf.conf

the dir mounted empty! its that right? (did nothing on the web interface yet!)
I also noted a /root/.influxdbv2 folder with any content! (user associated)

Screen Shot 2021-01-29 at 17.07.23

Anyway to create a db via command line, some selects/inserts? influx console?
influx on the command line gives me a list of commands! but when I did this!

# influx telegrafs
Error: At least one of org, org-id, or id must be provided. See 'influx telegrafs -h' for help

So what we did in the influxdb_cli container (?I suppose We have setted all those vars?)
also noticed the influxdb_cli was not running (anyway to auto configure without creating a container?)
When on localhost:8086, user/pass was asked! so I supposed its configured!

I found Different ways to query InfluxDB | InfluxDB OSS 2.0 Documentation
but I am not able to have the repl working (install flux?)

more to came, experimenting things here…

Hello @mvcorrea,
Have you had a chance to look at this?

I think it could be helpful to you, if you haven’t seen it already.

You need the influx_cli container to setup your influxdb instance all within a single docker-compose. Otherwise you could run telegraf outside of docker and visit the UI to perform the setup.

Hi there, Reading right now, thanks for your time…
Can you help me with the remaining loose ends?
now using 2.0.4r0 and lets remove docker out of the equation to make it simpler!

  • new fresh influxd daemon running…
  • running “influx setup” from command line creates file /etc/influxdb2/influx-configs.
    – no user and pass stored in this file! where does it stays?
    – anyway to drop a file in a folder and the daemon get its configuration (full setup)?
    – the situation here is where/what files are used to initialize the DB?
    – in your docker-compose you mentioned “/.influxdbv2” volume! how does it relate?
  • I also got the command “influxd print-config”
    – I am able to saw user related path in it “/root/.influxdbv2/influxd.bolt | engine” in this output
    – this file should stay in “/etc/influxdb2/config.yml” but there is none right now
    – why user associated config files here?

summarising the situation here, in order to deploy influxdb we should need the proper files in its proper places, then start the daemon! unfortunately I am not able to find this specific documentation, can you help me with this?


Hi @mvcorrea, glad to see somebody testing out the rc0 build!

The /etc/influxdb2/influx-configs file written by influx setup will contain an auth token that you can use to authenticate requests to all V2 APIs. The username/password combo you use in setup will never be written in plaintext or returned by an API call, but you shouldn’t need it to make V2 requests.

The default config file in the rc0 build is stored at /etc/defaults/influxdb2/config.yml. It’s stored there because of technical limitations w/ Docker, to make sure it’s still available if an empty directory is mounted at /etc/influxdb2. Ideally, you shouldn’t ever need to read that file directly. Instead, I’d advise doing this:

# Get the full default config as a local file
docker run --rm \ \
  influxd print-config > config.yml

# Edit config.yml

# Run the container w/ the custom config mounted
docker run --rm \
  -p 8086:8086 \
  -v $(pwd)/config.yml:/etc/influxdb2/config.yml \

We’ll be releasing 2.0.4 with updated documentation to DockerHub early next week, it will have more examples that (hopefully) help you get started.