InfluxDB init process failing (resolved)


I try to run InfluxDB in a container. Initially, I need to configure the database (Users, Databases, Retention policies etc.) when container starts.

InfluxDB docker documentation states:

Initialization Files
If the Docker image finds any files with the extensions .sh or .iql inside of the /docker-entrypoint-initdb.d folder, it will execute them. The order they are executed in is determined by the shell. This is usually alphabetical order.

I’ve created a simple script create_db.iql which looks like this:


And added it in my Dockerfile and built an image called influx:

FROM influxdb:1.5.1
ADD influxdb.conf /etc/influxdb/
ADD create_db.iql /docker-entrypoint-initdb.d/

Then when I start my container from influx image I get the following:

Creating influxdb ... done
Attaching to influxdb
influxdb    | influxdb init process in progress...
influxdb    | ts=2018-04-02T16:30:46.718202Z lvl=info msg="InfluxDB starting" log_id=07DnzykW000 version=1.5.1 branch=1.5 commit=cdae4ccde4c67c3390d8ae8a1a06bd3b4cdce5c5
influxdb    | ts=2018-04-02T16:30:46.718267Z lvl=info msg="Go runtime" log_id=07DnzykW000 version=go1.9.2 maxprocs=2
influxdb    | ts=2018-04-02T16:30:46.821429Z lvl=info msg="Using data dir" log_id=07DnzykW000 service=store path=/var/lib/influxdb/data
influxdb    | ts=2018-04-02T16:30:46.821472Z lvl=info msg="Open store (start)" log_id=07DnzykW000 service=store trace_id=07Dnzz9G000 op_name=tsdb_open op_event=start
influxdb    | ts=2018-04-02T16:30:46.821501Z lvl=info msg="Open store (end)" log_id=07DnzykW000 service=store trace_id=07Dnzz9G000 op_name=tsdb_open op_event=end op_elapsed=0.030ms
influxdb    | ts=2018-04-02T16:30:46.821521Z lvl=info msg="Opened service" log_id=07DnzykW000 service=subscriber
influxdb    | ts=2018-04-02T16:30:46.821526Z lvl=info msg="Starting monitor service" log_id=07DnzykW000 service=monitor
influxdb    | ts=2018-04-02T16:30:46.821530Z lvl=info msg="Registered diagnostics client" log_id=07DnzykW000 service=monitor name=build
influxdb    | ts=2018-04-02T16:30:46.821535Z lvl=info msg="Registered diagnostics client" log_id=07DnzykW000 service=monitor name=runtime
influxdb    | ts=2018-04-02T16:30:46.821539Z lvl=info msg="Registered diagnostics client" log_id=07DnzykW000 service=monitor name=network
influxdb    | ts=2018-04-02T16:30:46.821781Z lvl=info msg="Registered diagnostics client" log_id=07DnzykW000 service=monitor name=system
influxdb    | ts=2018-04-02T16:30:46.821983Z lvl=info msg="Starting precreation service" log_id=07DnzykW000 service=shard-precreation check_interval=10m advance_period=30m
influxdb    | ts=2018-04-02T16:30:46.821995Z lvl=info msg="Starting snapshot service" log_id=07DnzykW000 service=snapshot
influxdb    | ts=2018-04-02T16:30:46.821999Z lvl=info msg="Starting continuous query service" log_id=07DnzykW000 service=continuous_querier
influxdb    | ts=2018-04-02T16:30:46.822005Z lvl=info msg="Starting HTTP service" log_id=07DnzykW000 service=httpd authentication=true
influxdb    | ts=2018-04-02T16:30:46.822025Z lvl=info msg="opened HTTP access log" log_id=07DnzykW000 service=httpd path=stderr
influxdb    | ts=2018-04-02T16:30:46.822055Z lvl=info msg="Listening on HTTP" log_id=07DnzykW000 service=httpd addr= https=false
influxdb    | ts=2018-04-02T16:30:46.822051Z lvl=info msg="Storing statistics" log_id=07DnzykW000 service=monitor db_instance=_internal db_rp=monitor interval=10s
influxdb    | ts=2018-04-02T16:30:46.822089Z lvl=info msg="Starting retention policy enforcement service" log_id=07DnzykW000 service=retention check_interval=30m
influxdb    | ts=2018-04-02T16:30:46.822217Z lvl=info msg="Sending usage statistics to" log_id=07DnzykW000
influxdb    | ts=2018-04-02T16:30:46.822400Z lvl=info msg="Listening for signals" log_id=07DnzykW000
influxdb    | [httpd] - - [02/Apr/2018:16:30:47 +0000] "GET /ping HTTP/1.1" 204 0 "-" "InfluxDBShell/1.5.1" 32ec53f2-3693-11e8-8001-000000000000 95
influxdb    | [httpd] - - [02/Apr/2018:16:30:47 +0000] "POST /query?chunked=true&db=&epoch=ns&q=SHOW+DATABASES HTTP/1.1" 403 87 "-" "InfluxDBShell/1.5.1" 32ec6705-3693-11e8-8002-000000000000 157
influxdb    | influxdb init process in progress...
influxdb    | [httpd] - - [02/Apr/2018:16:30:48 +0000] "GET /ping HTTP/1.1" 204 0 "-" "InfluxDBShell/1.5.1" 3385d058-3693-11e8-8003-000000000000 27
influxdb    | [httpd] - - [02/Apr/2018:16:30:48 +0000] "POST /query?chunked=true&db=&epoch=ns&q=SHOW+DATABASES HTTP/1.1" 403 87 "-" "InfluxDBShell/1.5.1" 3385e0e4-3693-11e8-8004-000000000000 55
influxdb    | influxdb init process in progress...
influxdb    | [httpd] - - [02/Apr/2018:16:30:49 +0000] "GET /ping HTTP/1.1" 204 0 "-" "InfluxDBShell/1.5.1" 341f1cd6-3693-11e8-8005-000000000000 27
influxdb    | [httpd] - - [02/Apr/2018:16:30:49 +0000] "POST /query?chunked=true&db=&epoch=ns&q=SHOW+DATABASES HTTP/1.1" 403 87 "-" "InfluxDBShell/1.5.1" 341f2f19-3693-11e8-8006-000000000000 89
influxdb    | influxdb init process in progress...
influxdb    | [httpd] - - [02/Apr/2018:16:38:19 +0000] "GET /ping HTTP/1.1" 204 0 "-" "InfluxDBShell/1.5.1" 403d2dbb-3694-11e8-803b-000000000000 26
influxdb    | [httpd] - - [02/Apr/2018:16:38:19 +0000] "POST /query?chunked=true&db=&epoch=ns&q=SHOW+DATABASES HTTP/1.1" 403 87 "-" "InfluxDBShell/1.5.1" 403d3cce-3694-11e8-803c-000000000000 62
influxdb    | influxdb init process in progress...
influxdb    | influxdb init process failed.
influxdb exited with code 1

InfluxDB can not overcome initialization stage.
There are 3 things looking weird to me:

  1. Sending usage statistics to What is this for? I don’t want that.
  2. The pair of GET + POST requests. Where did they came from? POST issues SHOW DATABASES command, but either no admin user was created yet, or it was created (definitely not by my script, since password is “admin” not “password”) so the request can not authenticate and receives 403 back. In any case, this is strange.
  3. Finally, “influxdb init process in progress…”, and “influxdb init process failed.” indicates that my simple script was not run successfully (and it wasn’t indeed). I do not know if that correlates with 1) and 2) but why is that happening?

Could you please tell me what am I doing wrong and how to fix this?

I’m not sure if this helps, but when influxdb starts up in my environments, Listening for signals, is the last startup related message. After that, there’s a gap in time, until my first queries, or post(write) calls happen.
Perhaps the Docker stuff has some extra stuff to check if the database came up. Using “Show Databases” is a good way to check if the database is up and running. I use it in my java code when interacting with influx to make sure it’s running.
But, that’s just a guess. I’ve never used the Docker image of influx yet.
I hope this helps.

Thank you @Jeffery_K for your answer!
However, the problem was the following: There are a set of predefined environment variables which InfluxDB container will look at and will make some initialization action based them. The most important ones are INFLUXDB_ADMIN_USER and INFLUXDB_ADMIN_PASSWORD. The very first thing InfluxDB will do is creating a user with all privileges (administrator user) with login and password specified in the variables mentioned. Then it will run every .iql script on behalf of this admin user. And if you think carefully - that is logical, since you can not run InfluxDB commands if authorization is enabled but you are not authorized.

What I’ve tried to do instead (actually I had some legacy code, which has never been tested :sweat_smile: ) was the attempt to create admin user from inside those .iql scripts and configure everything else after.
Although, admin user was actually created with defaults login and password “admin”/“admin” but the script was failing on the first container start.

Conclusion: it is better to specify INFLUXDB_ADMIN_USER and INFLUXDB_ADMIN_PASSWORD from the outside and pass it as docker environment variables instead of trying to create admin user from the initialization script.