6

In previous versions of influxdb we could create an admin user by using the environment variables

influxdb:
    ...
    environment:
        INFLUXDB_HOSTNAME: "${INFLUXDB_HOSTNAME}"
        INFLUXDB_USERNAME: "${INFLUXDB_USERNAME}"
        INFLUXDB_PASSWORD: "${INFLUXDB_PASSWORD}"
    ...

But in version 2.0 these env. variables are removed

What I want to achieve is, when I run the docker-compose up my_influx_db

It should create a default admin user, if it doesn't exist

What I tried so far is:

my_influx_db:
  image: quay.io/influxdb/influxdb:v2.0.3
  hostname: my_influx_db
  container_name: my_influx_db
  ports:
    - 8086:8086
  command: /bin/sh -c "exec influxd && sleep 10 && influx setup -o test_org -b test_bucket -u user1 -p testpassword -f"

docker-compose up my_influx_db starts the influxdb, but doesn't run the setup script after 10 secs

What is the right way to create default admin user?

Edit: I managed to run it with the following configuration, but is it the right way to do it?

command: /bin/sh -c "(sleep 10 && echo setting up user && influx setup -o test_org -b test-bucket -u influxdb -p influxdb -f) & influxd"
Bekjan Juma
  • 453
  • 1
  • 5
  • 11

2 Answers2

9

The latest version: 2.0.7 of influxdb made it easier providing the ability to create initial admin username and password

https://docs.influxdata.com/influxdb/v2.0/upgrade/v1-to-v2/docker/#influxdb-2x-initialization-credentials

enter image description here

Bekjan Juma
  • 453
  • 1
  • 5
  • 11
6

You can up another container which will try to create a user. So it's my docker-compose.yml:

version: '3'
services:
  influxdb:
    image: quay.io/influxdb/influxdb:v2.0.4
    container_name: influxdb
    volumes:
      - ./influxdbv2:/root/.influxdbv2
    ports:
      - "8086:8086"
  influxdb_cli:
    links:
      - influxdb
    image: quay.io/influxdb/influxdb:v2.0.4
    entrypoint: influx setup --bucket test_bucket -t test_token -o test_org --username=test_username --password=test_password --host=http://influxdb:8086 -f

    restart: on-failure:20
    depends_on:
      - influxdb
volumes:
  influxdbv2:

Amerousful
  • 2,292
  • 1
  • 12
  • 26
  • Thanks, @Amerousful. Yeah, I already did this way. The only downside of this solution is that we create an extra container just for one time operation – Bekjan Juma Mar 03 '21 at 15:43