Best practice of stopping InfluxDB inside a docker container without stopping the container

I need to create a new operator token for my instance running in a docker container since I don’t have one. Following this conversation on GitHub, I got to the point, where I entered
influxd recovery auth create-operator --org xxx --username yyy --bolt-path /var/lib/influxdb2/influxd.bolt
inside the container but I got the Error
Error: unable to open boltdb file unable to open boltdb file timeout
which is the result of running this command while influxDB is still running. Now, I have to stop the influxd process, run the command above and restart the InfluxDB Server. What is the best practice of doing so? I could just kill the influxd process, but I thought that there has to be a better option.
The ìnfluxd CLI command has no subcommand stop, so how can I do this elegantly?

In general, you can send a CTRL+C (SIGINT) to stop the process and it will do the necessary cleanup before shutting down. That will also shut the container down.

If you want to run commands against the DB (as you indicated by wanting to run influxd recovery), the best was it to run the same image with all the same flags, but with /bin/bash at the end. This will drop you into a shell that you can use to execute any commands you need to. The next time you start the container, start it without /bin/bash at the end and it should start you back up into influxdb

Thanks for your answer. I am running the influxDB instance with an grafana instance via a docker compose file, but I replicated the mounted volumes and environment variables in a docker run command, stopped the original influx container and started the new version with the /bin/bash command at the end to override the original entrypoint. I tried the influxd recovery command again, but I got the following error:

2023-02-07T08:15:20.629657Z	info	Resources opened	{"log_id": "0frjwtCl000", "system": "bolt-kvstore", "path": "/var/lib/influxdb/influxd.bolt"}
Error: bucket "authorizationsv1": bucket not found
See 'influxd -h' for help

It seems like the command found the database and opened it, but it still could not find the “authorizationsv1” bucket. Is there another way of fixing this issue?

In the GitHub Thread, you mentioned that it is possible to log into the CLI with the user that created the Database, which gives you operator token permissions. I searched for a “login” subcommand for the influx and influxd commands but didn’t found anything in the docs. Could you link me a documentation page on how to log in using the CLI?

For the first part, my guess would be something is wrong with the pathing of your volume and the bolt file is not actually there. Looks like you have /var/lib/influxdb/influxd.bolt and you might want /var/lib/influxdb2/influxd.bolt? You can also verify on your local machine if that bucket actually exists by using the boltdbweb tool to inspect the file. If that bucket is not there, something has gone wrong writing the file, and if it is there then it may be a recovery bug.

The Release notes have a bit of an explanation and a link out to the rest of the docs that may help explain the login capability influx CLI release notes | InfluxDB OSS 2.6 Documentation

Thanks for your advise. The path was correct, I just copied the command from the GitHub Conversation, which had the influxdb2 folder. I also verified the existence of the bucket with the Tool you linked on my local machine. At that moment I wanted to try the influxd recovery command locally with the copy of the .bolt db and this time, it worked! I’m not sure why the command failed on my VM, but maybe some Docker magic prevented it from being accessed properly. I transferred the modified file over to the VM and restarted my Docker container. The new operator token is being shown by the Influx UI.

can you clarify how you were able to run influxd recovery outside of the container? I’m in the same boat as you were, and I’d like to try the same solution.

1 Like

I did this two years ago, but if I remember correctly, I simply installed a local influxdb instance on my machine and replaced the .bolt db file with the one from the docker container. After that, I ran the influxd command.

2 Likes

Thanks, I got it! For anyone looking for instructions, here’s what I did.

  1. Stop the Influxdb container.
  2. Go to the persistent location of your influxd.bolt file and make a backup copy: cp influxd.bolt influxd.bolt.BAK
  3. Move your influxd.bolt file to a machine where you can install Influxdb natively (that is, not in a docker container). Adjust permissions as necessary.
    For me, this was my Windows machine. For others, the docker host machine may be fine for this purpose.
  4. Install Influxdb on this machine from here: Install InfluxDB OSS v2 | InfluxDB OSS v2 Documentation
    Follow the instructions to install, but don’t go any further – we don’t want to actually start influx on this machine.
  5. Open a terminal window in the location where influxd.exe is.
  6. Run the recovery auth create-operator .\influxd recovery auth create-operator --bolt-path [location of the bolt file from step 3] --username admin --org [your org]
  7. Move the now updated influxd.bolt file back to the original location from step 2
  8. Adjust the ownership and permissions of influxd.bolt to match influxd.bolt.BAK
  9. Restart the Influxdb container.
1 Like

@tkohhh Thank you for sharing your solution!