influxdata / influxdata-docker

Official docker images for the influxdata stack
324 stars 248 forks source link

Not able to create multiple DBs at docker run #260

Open lvrfrc87 opened 6 years ago

lvrfrc87 commented 6 years ago

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.

psreekala commented 6 years ago

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

lvrfrc87 commented 5 years ago

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

zimmertr commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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