Docker - InfluxDB 2.x Container Setup


InfluxDB is a time series database. In my case I store sensor data from Home Assistant in this database. But also price information from the stock exchange. And that works very well. InfluxDB also has its own reporting module, but you can also use Grafana for that (as I do).

An interesting alternative to InfluxDB is QuestDB. I’m experimenting with that too.

Here I describe my setup of the Docker InfluxDB container. I run this Docker container on a Ubuntu VM that runs via [[ Proxmox VE ]]. I perform the following on the CLI.

Docker pull command:

docker pull influxdb

Within my home folder I have created a Docker folder where I create a subfolder for each container:

cd ~
mkdir -p docker/influxdb
cd docker/influxdb

Also create folders where the InfluxDB data and config files can be stored:

mkdir data
mkdir config

I use the Nano text editor to create a shell script:

sudo nano influxdb_run.sh

With this shell script we are going to create the container. Copy the following into influxdb_run.sh:

IDu=$(id -u $(logname)) # Saves the logged in user id in the IDu variable
IDg=$(id -g $(logname)) # Saves the logged in user group in the IDg variable

docker run -d \
 --name=influxdb \
 --hostname=influxdb \
 --ulimit nofile=32768:32768 \
 -p 3004:8086 \
 -v $PWD/data:/var/lib/influxdb2 \
 -v $PWD/config:/etc/influxdb2 \
 -v /etc/localtime:/etc/localtime:ro \
 -e TZ=Europe/Amsterdam \
 -e DOCKER_INFLUXDB_INIT_MODE=setup \
 -e DOCKER_INFLUXDB_INIT_USERNAME=USER \
 -e DOCKER_INFLUXDB_INIT_PASSWORD=PASS \
 -e DOCKER_INFLUXDB_INIT_ORG=YOUR-ORG \
 -e DOCKER_INFLUXDB_INIT_BUCKET=YOUR-BUCKET \
 --restart unless-stopped \
 influxdb:latest

If necessary, adjust the following:

–ulimit nofile=32768:32768
This setting is to prevent too many open files errors. You can get this error during bulk import of data (csv import or for example the batch node in Node-RED) in InfluxDB

-p 3004:8086
Choose a port that is still available, I chose 3004. Check this with netstat

-v $PWD/data:/var/lib/influxdb2
Choose the location for the Influxdb2 data. In this example it is the data map we created

-v $PWD/config:/etc/influxdb2
Choose the location for the Influxdb2 config. In this example it is the config map we created

-e TZ=Europe/Amsterdam
Pick the right timezone

-e DOCKER_INFLUXDB_INIT_USERNAME=USER
Replace USER with your own username

-e DOCKER_INFLUXDB_INIT_PASSWORD=PASS
Replace PASS with your own password

-e DOCKER_INFLUXDB_INIT_ORG=YOUR-ORG
Replace YOUR-ORG with your own organization name - I used the name of the VM so UbuntuVM

-e DOCKER_INFLUXDB_INIT_BUCKET=YOUR-BUCKET
Replace YOUR-BUCKET with your own bucket name - I use the name of the container, for example homeassistant

Exit Nano (CTRL-X) and save the changes.

Now create the container:

sudo sh influxdb_run.sh

Check if the container is running properly.

See also my notes about updating containers with Portainer or via the CLI. With Synology’s Docker Application, updating a container is also very easy.

Using InfluxDB

InfluxDB can now be accessed via the following URL:

http://<IP DOCKER HOST>:3004/

In addition to the Home Assistant bucket, I also use a bucket to store stock exchange data from an API. For testing I use ‘sandbox’ measurements. You can read here how to remove measurements with for example test data


Read other notes

Comments

    No comments found for this note.

    Join the discussion for this note on this ticket. Comments appear on this page instantly.

    Tags


    Notes mentioning this note

    • Docker - QuestDB Container Setup
      QuestDB is a high-performance, open-source SQL database. QuestDB’s stack is engineered from scratch, zero-GC Java and dependency-free. It includes endpoints...

    Notes Graph