influxdata-docker icon indicating copy to clipboard operation
influxdata-docker copied to clipboard

Not able to create multiple DBs at docker run

Open lvrfrc87 opened this issue 7 years ago • 5 comments

Hi, I am trying to create multiple databases using -e option:

docker run --name db -d \ -e INFLUXDB_DB=ping_rtt -e INFLUXDB_DB=tcp_rtt \ -e INFLUXDB_ADMIN_USER=root -e INFLUXDB_ADMIN_PASSWORD=supersecretpassword \ -v $PWD/influxdb/influxdb.conf:/etc/influxdb/influxdb.conf:ro \ -v $PWD/influxdb:/var/lib/influxdb \ influxdb

However, with this command, just INFLUXDB_DB=tcp_rtt is executed. Not sure if is an issue or not but your help will be greatly appreciated.

lvrfrc87 avatar Sep 28 '18 15:09 lvrfrc87

Hi Federico..any luck with creating multiple databases this way?

psreekala avatar Oct 26 '18 04:10 psreekala

No unfortunately. What need to be done I believe is to create a loop into init-influxdb.sh

https://github.com/influxdata/influxdb/blob/master/docker/init-influxdb.sh

I would like to give a try as soon as I have time

lvrfrc87 avatar Oct 26 '18 07:10 lvrfrc87

I started looking for a solution to this problem today too. I discovered someone managed to do it this way but it's not working for me.

https://github.com/influxdata/influxdata-docker/issues/251

Did you two find a different solution?

zimmertr avatar Oct 16 '19 17:10 zimmertr

Figured out a way actually. With Kubernetes at least. By providing a lifecycle policy you can execute a command on the pod after it has been launched. For example:

                  lifecycle:
                      postStart:
                          exec:
                              command:
                                  - "/bin/sh"
                                  - "-c"
                                  - >
                                      until curl -sL -I localhost:8086/ping > /dev/null; do
                                          echo 'InfluxDB is not yet ready.'
                                          sleep 1
                                      done

                                      echo 'InfluxDB is now ready.'
                                      influx -password '${INFLUXDB_ADMIN_PASSWORD}' -username '${INFLUXDB_ADMIN_USER}' -execute '{{ influxdb_cmds }}'

Where the INFLUXDB_ADMIN_PASSWORD and INFLUXDB_ADMIN_USER variables are configured in the env section of my Kubernetest manifest and the influxdb_cmds variable is injected via Ansible as a jinja template.

influxdb_cmds: 'CREATE DATABASE proxmox; CREATE DATABASE unifi'

zimmertr avatar Oct 16 '19 18:10 zimmertr

Actually, never mind. There is a different official way to accomplish this. The docker container supports dropping .sh files to configure the database server. Search the docs here for /docker-entrypoint-initdb.d

https://hub.docker.com/_/influxdb

zimmertr avatar Oct 16 '19 19:10 zimmertr