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"
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: