Skip to content

InfluxDB 2.x container setup

Introduction

InfluxDB is a time series database. I store data from Home Assistant in this database. InfluxDB has its own reporting module, but you can also use Grafana.

An interesting alternative to InfluxDB is QuestDB. I’m [[Docker - QuestDB Container Setup|experimenting]] with that too.

Setup

  1. Create the folders needed by the container

    Run the following commands inside your home folder:

    # Open your terminal application
    cd ~
    mkdir -p influxdb/data
    mkdir -p influxdb/config
    cd influxdb
  2. Create the script needed to run the container

    Save the following script as influxdb_run.sh:

    influxdb_run.sh
    # To create this script use your text editor application, for example Nano
    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 DOCKER_INFLUXDB_INIT_MODE=setup \
    -e DOCKER_INFLUXDB_INIT_USERNAME=<username> \
    -e DOCKER_INFLUXDB_INIT_PASSWORD=<password> \
    -e DOCKER_INFLUXDB_INIT_ORG=<organization> \
    -e DOCKER_INFLUXDB_INIT_BUCKET=<bucket> \
    -e TZ=Europe/Amsterdam \
    --restart unless-stopped \
    influxdb:latest
    # IMPORTANT: Please read the instructions below
    Instructions:
    • Optional Replace docker with podman if needed
    • Optional Remove --ulimit nofile=32768:32768 if not needed. This setting is to prevent too many open files errors. You can get this error during bulk import of (csv) data, or for example by using the InfluxDB batch node in Node-RED (!!!!! TODO LINK !!!!!!)
    • Required Replace port number 3004 (on the left side of :) with a port number that is available if needed
    • Optional Replace $PWD/config with the location of your config if needed. This can be a fileserver mount
    • Optional Replace $PWD/data with the location of your data if needed. This can be a fileserver mount
    • Required Replace <username> with your own username
    • Required Replace <password> with your own password
    • Required Replace <organization> with your own organization name. I used the name of my virtual machine for example
    • Required Replace <bucket> with your own bucket name. Because data of Home Assistant is stored I used homeassistant
    • Required Replace Europe/Amsterdam with your own timezone
  3. Run the script to create the container

    Run the following command:

    # Open your terminal application
    sudo sh influxdb_run.sh

    The image influxdb is automatically pulled and the container is created.

  4. Check the results

    If needed you can check if the container is running properly.

    Now you can use InfluxDB by opening a web browser and going to: http://localhost:3004. Replace localhost with the relevant IP address or FQDN if needed, and adjust the port if you changed it earlier.

Favorites

Comments

    No comments found for this note.

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

    Copyright 2021- Fiction Becomes Fact