Is it possible to configure influxdb 2.x user (and get token) without using cli/web ui

I would like to deploy influxdb with docker compose and set it up without needing to use cli/web UI

Influxdb would not be accessable to anywhere else than the docker composes network (which would contain telegraf + some python)

Currently when I try to deploy the docker-compose I need to

  1. Start influx container
  2. Use the influxd cli to setup user + org
  3. Generate auth token
  4. restart the whole compose

I would like to be able to specify needed things with environment variables/configuration files but I have not found any help to it at influx 2.0 documentation. InfluxDB configuration options | InfluxDB OSS 2.0 Documentation specifies that

Specifies the data store for secrets such as passwords and tokens. Store secrets in either the InfluxDB internal BoltDB or in Vault.

but I have not found a way to set the values.

Any help would be appreciated

@juha-ylikoski The influx CLI should be installed as part of the image, so you could script the token retrieval in your compose settings:

$(influx auth list --json | jq -r '.[].token')

There is a draft PR that includes a docker.compose file here. If you use this PR, be sure to update all the 9999 ports to 8086.

Hi thanks for your reply. I was not able to find the pr you meant but I found Influx v2 - telegraf configuration on docker - #3 by Anaisdg which gave me idea to use separate container for influx-cli for setup

Container I added to my compose:

    # From influxdb docs
    image: influxdb:2.0.4
    restart: unless-stopped
    container_name: influxdb
    - database
      - "8086:8086"
      - ../influx/influxdb2:/var/lib/influxdb2
    command: influxd run --reporting-disabled
    #  initializes influxdb user/password/bucket...
    image: influxdb:2.0.4
    container_name: influx-cli
    - database
      - influxdb
    command: sh -c 'sleep 5; influx setup --bucket "${INFLUX_DATA_BUCKET}" --token "${INFLUXDB_V2_TOKEN}" --org "${INFLUXDB_V2_ORG}" --username=${INFLUX_USERNAME} --password=${INFLUX_PASSWORD} --host=http://influxdb:8086 --force'
1 Like