Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database initialization is not working #232

Open
cpang2 opened this issue May 23, 2018 · 20 comments
Open

Database initialization is not working #232

cpang2 opened this issue May 23, 2018 · 20 comments

Comments

@cpang2
Copy link

cpang2 commented May 23, 2018

Tried to create database user and database in docker-compose.yml but it is not working. Nothing gets created. Please advise.

influxdb:
image: influxdb:latest
restart: always
container_name: influxdb
ports:
- "8086:8086"
environment:
- INFLUXDB_ADMIN_USER=USERNAME
- INFLUXDB_ADMIN_PASSWORD=PASS
- INFLUXDB_DB=DBTEST
- INFLUXDB_HTTP_ENABLED=true
- INFLUXDB_HTTP_AUTH_ENABLED=true

@dawidchyrzynski
Copy link

Any progress on this? I have the same issue when auth is enabled.

@dawidchyrzynski
Copy link

I've fixed the issue by escaping "true" value for INFLUXDB_HTTP_AUTH_ENABLED variable. My compose service looks like this now:

influxdb:
  image: influxdb:latest
  restart: always
  container_name: influxdb
  ports:
    - 8086:8086
  environment:
    INFLUXDB_DB: telemetry
    INFLUXDB_ADMIN_USER: influx_admin
    INFLUXDB_ADMIN_PASSWORD: pass
    INFLUXDB_HTTP_AUTH_ENABLED: "true"

@cpang2 can you confirm whether it works for you?

@repomaa
Copy link

repomaa commented Jul 5, 2018

Having the same issue. Passing true as a string does not fix it.

@IronSinew
Copy link

IronSinew commented Jul 5, 2018

I am also seeing this issue

environment:
     - INFLUXDB_DB=database
     - INFLUXDB_ADMIN_USER=admin
     - INFLUXDB_ADMIN_PASSWORD=admin
     - INFLUXDB_HTTP_AUTH_ENABLED=true

Database is not initialized. Users are not created.

@mmodenesi
Copy link

mmodenesi commented Jul 23, 2018

Same issue, using docker-compose version 1.19.0, build 9e633ef

edit:

Sorry, my bad. Using image: "influxdb:latest" fixed it (I was using an old version before). So I can not reproduce this, but maybe you can confirm (after container is created) that your influxdb image (latest) is indeed a recent one.

@emriver
Copy link

emriver commented Aug 27, 2018

As mentionned by @PSanetra in another thread, cleaning my influxdb volume fixed it for me (rm -rf /influxDbData)

@scho
Copy link

scho commented Nov 12, 2018

I ran into a similar issue. I've set INFLUXDB_DB, but no database was created.

There was an issue with the special characters not being properly escaped. In my case, the database was called metrics-live and the problem was the hyphen. I had to add quotes to the name, so that it worked ("metrics-live").

@halfbaked
Copy link

thanks to the comment above from @emriver . cleaning the volume fixed it for me.

@blockloop
Copy link

My problem was having influxd in my command:. The docker CMD executes a script which is a proxy to the influxd command, which executes all of the init stuff first.

OLD:

  influxdb:
    image: docker.io/influxdb:latest
    environment:
      - INFLUXDB_DB=prometheus
    volumes:
      - ./influxdb.conf:/etc/influxdb/influxdb.conf
    command:
      - 'influxd'
      - '-config'
      - '/etc/influxdb/influxdb.conf'

NEW:

  influxdb:
    image: docker.io/influxdb:latest
    environment:
      - INFLUXDB_DB=prometheus
    volumes:
      - ./influxdb.conf:/etc/influxdb/influxdb.conf
    command:
      - '-config'
      - '/etc/influxdb/influxdb.conf'

@lchachurski
Copy link

This is what worked for me using docker-compose. Keep in mind it doesn't work well when changing those settings back and forth. Once the database is initialized it will somehow rebel against changes and output weird errors while authenticating. In my case deleting /tmp/influxdb directory helped.

So delete any database dir first and then use the config below:

    influxdb:
        environment:
            INFLUXDB_DB: project_dev
            INFLUXDB_ADMIN_USER: admin
            INFLUXDB_ADMIN_PASSWORD: secret
            INFLUXDB_HTTP_AUTH_ENABLED: "true"
        image: influxdb:latest
        ports:
            - "8086:8086"
            - "8087:8082"
        volumes:
            - /tmp/influxdb:/var/lib/influxdb

@Surfict
Copy link

Surfict commented May 5, 2020

Hello, still have the problem with the current version.

@cooling75
Copy link

... Keep in mind it doesn't work well when changing those settings back and forth. Once the database is initialized it will somehow rebel against changes and output weird errors while authenticating. In my case deleting /tmp/influxdb directory helped.

Thank you for this hint, I struggled with this for hours. Deleting the volume and let docker-compose recreate it solved it.

@JoshEisele
Copy link

This issue is quite old - is there any hope that it will be fixed at all. Any workaround to set the ADMIN_USER, ADMIN_PASSWORD as well as the option to HTTP_AUTH_ENABLED at initial docker-compose?

@elboletaire
Copy link

Checking the init-influxdb.sh file, I see that the only way to initialize users in influx is by setting both INFLUXDB_HTTP_AUTH_ENABLED and INFLUXDB_ADMIN_USER. At the beginning of the init-influxdb.sh there's an initialization of a variable named INIT_USERS, which is then used to check if db initialization should be made.

INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)

I have checked it and it properly initializes the db and creates the user if you specify all the required variables.

I've stumbled upon this issue for a different thing though (I'll create a different issue for it right away): if you specify a command it's completely ignored, even though it's specified in the official readme:

imatge

@iosonoumberto
Copy link

Hello,
same problem using both latest and 1.8 using docker file

env should be correct (this is from my docker-compose.yml file)

    environment:
      INFLUXDB_DB: jlogs
      INFLUXDB_ADMIN_USER: admin
      INFLUXDB_ADMIN_PASSWORD: admin
      INFLUXDB_HTTP_AUTH_ENABLED: "true"

It should work as I have both ADMIN USER and HTTP AUTH enabled
moreover, inside container, i see the env vars

root@335d30cd03d4:/# env | grep INFL
INFLUXDB_DB=jlogs
INFLUXDB_ADMIN_USER=admin
INFLUXDB_HTTP_AUTH_ENABLED=true
INFLUXDB_VERSION=1.8.3
INFLUXDB_ADMIN_PASSWORD=admin

so it has everything to create user and db...in theory

i can see these logs

[httpd] 127.0.0.1 - - [22/Oct/2020:22:37:28 +0000] "GET /ping HTTP/1.1" 204 0 "-" "InfluxDBShell/1.8.3" 2a348f04-14b7-11eb-8001-0242c0a85002 759
ts=2020-10-22T22:37:28.460603Z lvl=info msg="Executing query" log_id=0Q0cCQ90000 service=query query="CREATE USER admin WITH PASSWORD [REDACTED] WITH ALL PRIVILEGES"
[httpd] 127.0.0.1 - - [22/Oct/2020:22:37:28 +0000] "POST /query?chunked=true&db=&epoch=ns&q=CREATE+USER+%22admin%22+WITH+PASSWORD+%5BREDACTED%5D+WITH+ALL+PRIVILEGES HTTP/1.1" 200 57 "-" "InfluxDBShell/1.8.3" 2a34bf6a-14b7-11eb-8002-0242c0a85002 126506

and these logs

[httpd] 127.0.0.1 - admin [22/Oct/2020:22:37:28 +0000] "GET /ping HTTP/1.1" 204 0 "-" "InfluxDBShell/1.8.3" 2a4a8069-14b7-11eb-8003-0242c0a85002 99
ts=2020-10-22T22:37:28.702907Z lvl=info msg="Executing query" log_id=0Q0cCQ90000 service=query query="CREATE DATABASE jlogs"
[httpd] 127.0.0.1 - admin [22/Oct/2020:22:37:28 +0000] "POST /query?chunked=true&db=&epoch=ns&q=CREATE+DATABASE+jlogs HTTP/1.1" 200 57 "-" "InfluxDBShell/1.8.3" 2a4a9d28-14b7-11eb-8004-0242c0a85002 108868

Anyhow, if i check on my local directory used for influx data i do not see the db created

[root@tig fig]# ls ../influxdb_data/data/
_internal

only internal db is created

as a result, when i go to grafana and try to create a data source it fails due to authorization issues (as i'm probably trying to 'connect' to a db that does not exist

Is there a working tag or something i can do to make it work?

@thomascrha
Copy link

Ok the issue for me was with the meta_data directory check with the in the if statement before the init stuff occurs.

if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d "$META_DIR" 2>/dev/null)" ]; then

The last part is checking if the $META_DIR directory exists - if it does it won't continue. This is important as it's what really see's if the init command have been run and if they needs to be run again. My problem is I don't want to use a volume but a bind - and I can't do that with /var/lib/influxdb - so I bind all the sub dirs to get around this i.e. data, wal and meta. When I do this I create the directory - disallowing the init stuff to work. To get around this I simply check if the directory contains any files rather than checking if the directory exists.

What I did was replaced

[ ! "$(ls -d "$META_DIR" 2>/dev/null)" ]

with

[ $(ls "$META_DIR" | wc -l  | grep -w "0") ]

@andcan86
Copy link

andcan86 commented Feb 5, 2021

Please specify the OS on which you run docker and the docker-compose version you are using.

BTW, it might have to do with the OS, on Windows 10 I have to use double quotes for the environement variables, so:

INFLUXDB_DB="db-test"

and it works. hope that helps!

@suadev
Copy link

suadev commented Jun 3, 2021

that's worked for me

  influxdb:
    image: influxdb:latest
    environment:
      DOCKER_INFLUXDB_INIT_MODE: setup
      DOCKER_INFLUXDB_INIT_USERNAME: admin
      DOCKER_INFLUXDB_INIT_PASSWORD: password
      DOCKER_INFLUXDB_INIT_ORG: myorg
      DOCKER_INFLUXDB_INIT_BUCKET: krakend
    ports:
      - "8086:8086"

@sailesh-suri
Copy link

If you're still using influxdb:1.8, you'll need to set a custom meta DB directory with the INFLUXDB_META_DIR environment variable. The /init-influxdb.sh script that's supposed to create your admin user account does not seem to function if you use the default meta directory. Not sure why it was designed that way. The below configuration is working for me.

  influxdb:
    image: influxdb:1.8
    ports:
      - "8086:8086"
    environment:
      - INFLUXDB_DB=default-db
      - INFLUXDB_HTTP_AUTH_ENABLED=true
      - INFLUXDB_ADMIN_USER=admin
      - INFLUXDB_ADMIN_PASSWORD=password
      - INFLUXDB_META_DIR=/var/lib/influxdb/meta2

@sakeebs
Copy link

sakeebs commented Mar 13, 2023

Do we have any solution for this, as after every restart of the container or docker service or server reboot I have to change the meta DIR variable.
I am upgrading the influx from 1.7 to 1.8.10

  • INFLUXDB_META_DIR=/var/lib/influxdb/meta2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests