InfluxDB Docker Compose: An efficient timeseries DB for Metrics

InfluxDB is a time series database, which is perfect for homelab monitoring. This InfluxDB Docker Compose guide shows you how to get started with InfluxDB in minutes.

I have been thinking about writing a series of guides for home lab and smart home monitoring using various databases, including InfluxDB and Prometheus, and Grafana. This is a step towards that.

First, I plan to cover the installation of individual components and then future posts will include example use cases and applications for homelab monitoring. I have integrated InfluxDB with Home Assistant, Prometheus, and Glances and used Grafana to visualize system resources, Docker container resource usage, smart sensor data, etc., and it has been awesome.

InfluxDB is one of apps that made it into our list of best Docker containers.

Let us first start with InfluxDB. In this post, I will share my working InfluxDB Docker Compose file and explain how to implement it in minutes. Be warned that we won't be doing any fancy dashboarding in this guide. I will cover those in future posts. So stay tuned.

What is InfluxDB?

InfluxDB is another TSDB developed by InfluxData to store and retrieve data records part of a "time series". The TSDB shows the context of the relationship between timestamped data points. Fast insertion and fast retrieval into InfluxDB are made possible with developer tools.

Influxdb Docker Compose Guide
Influxdb Time Series Database

Serverless real-time monitoring of large amounts of time-stamped data on a dashboarding engine with analytics service makes InfluxDB fast and elastic. Use cases include DevOps monitoring, application metrics, IoT sensor data, and real-time analytics supporting queries, tasks, and agents all in one place.

InfluxDB is tightly integrated with Telegraf, an agent for collecting metrics from various sources (similar to Prometheus exporter).

InfluxDB is a popular database choice for smart home sensors in Home Assistant. It works flawlessly with Grafana for dashboarding. [Read: Grafana Docker Compose: Build Awesome Dashboards]

Which databases do you use to store your metrics?

View Results

Loading ... Loading ...

InfluxDB Docker Compose Setup

Most Docker tutorials out there give you the Docker run command and ask you to copy-paste it into Portainer. [Read: Portainer Docker Compose: FREE & MUST-HAVE Container Manager]

Having used Docker for over 5 years (and being a person of non-IT background), I strongly suggest you take the time to learn Docker compose and build your stack using it.

Docker Compose gives you portability between systems. I can use the docker-compose files from my GitHub repo in my Ubuntu Server on Proxmox, my Ubuntu Server VPS on Digital Ocean, or even my Synology NAS and they will work the same.

Using Docker Compose for InfluxDB is, in my opinion, the easiest way.

1. Preparing to Setup InfluxDB Using Docker

If you already have docker and docker-compose installed and the docker environment setup (.env file), then skip to Docker Compose for InfluxDB section below.

Requirements

First, let us start with some requirements. I won't go into a lot of details as these have been covered in detail in my Docker Media Server guide. Here is a summary of the requirements before Proceeding.

Setting Up The Docker Environment

This is also explained in detail in my Docker Guide. We are going to customize a few things with Docker before building the InfluxDB Docker Compose file.

First, is the folder structure. I like to house all of the docker-related files and folders in one location. I call it the Docker Root Folder. Our docker-compose.yml file, .env file, etc. will be located in this folder, as shown below.

Docker Media Server Folder Structure
Docker Media Server Folder Structure

In addition, all of InfluxDB's data will go into the appdata/influxdb folder. For this guide, you do not need to worry about the remaining folders in the above screenshot.

Create the .env file

First, the dot in front of env is not a typo.

It is a hidden file that will store some of the key information we may use (environmental variables) repeatedly. In the docker root folder (explained above), create the .env file and add the following contents to it.

DOCKERDIR="/home/anand/docker"

Customizing the above variables is explained in detail in my Docker guide, along with the right permissions to set (very important!).

In short, DOCKERDIR is the docker root folder mentioned above.

Replace anand with your username.

2. Create the Base InfluxDB Docker Compose File

Before we go ahead and add the Docker Compose for InfluxDB, we will have to add a few basic elements to the compose file. Once again, this is all explained in detail in my Docker tutorial. But here is a summary of it.

Note that spacing and indentation are crucial in YAML files. Therefore, pay attention to the formatting when you copy-paste and customize the InfluxDB Docker Compose snippet.

In your Docker Compose file, if you do not already have it, add the following:

version: "3.9"

########################### NETWORKS
networks:
  default:
    driver: bridge

########################### SERVICES
services:

We are specifying the version of Docker Compose reference to use and the default Docker bridge network. If you do not know what these are, do not worry.

We are going to make InfluxDB accessible using the Docker Host machine's IP, using InfluxDB's default port (e.g. http://192.68.1.111:8086). If you are working on the Docker host, you can also use http://localhost:8086/. For this purpose, the above network block is sufficient.

3. Docker Compose for InfluxDB

Here is the Docker-Compose for InfluxDB that I use. Add it right under services (pay attention to indentation):

  # InfluxDB - Database for sensor data
  influxdb:
    image: influxdb:latest
    container_name: influxdb
    networks:
      - default
    security_opt:
      - no-new-privileges:true
    restart: unless-stopped
    ports:
      - "8086:8086"
    volumes:
      - $DOCKERDIR/appdata/influxdb2/config:/etc/influxdb2
      - $DOCKERDIR/appdata/influxdb2/db:/var/lib/influxdb2
You may find that the Docker Compose examples in my GitHub repo differ from the above. What is shown above is an example that is good for beginners to get started with. What is in my GitHub repo is my current setup with many features and security enhancements.

Customizing InfluxDB Docker Setup

Here are some notes to understand and customize the above InfluxDB docker-compose example:

  • We are using latest influxdb docker image.
  • InfluxDB will belong to the "default" network. This is fine for now. For advanced configurations, keep reading.
  • In the ports section, we are exposing port 8086 to the host, which is the default InfluxDB WebUI port. Therefore, InfluxDB will be available on the Docker host IP at port 8086. For example, my Docker host has an IP of 192.168.1.111. So InfluxDB will be available at http://192.168.1.111:8080.
  • Under volumes, we are mapping persistent volumes (config and db) for InfluxDB configuration and databases.

Customizing Network

In the above InfluxDB Docker Compose file, we set the network as default. This is fine.

Alternatively, you can specify the InfluxDB Docker container to use the host network. In this case, InfluxDB functions as if it were running natively on your host system. This requires all necessary ports to be free (e.g. 8086). To enable host networking, use the following block instead of networks:

    network_mode: 'host'

In addition, you will also need to remove the ports section. InfluxDB should be available at http://192.168.1.111:8086, which is the same URL as the default InfluxDB docker compose setup shown previously.

If for whatever reason, port 8086 is not free, you could specify a custom port on the host side (e.g. 8087:8086) or take a look at macvlan networking for docker.

Start InfluxDB

After customizing the InfluxDB Docker Compose file, you can start the InfluxDB container using the following command:

sudo docker compose -f ~/docker/docker-compose.yml up -d

Be sure to refer to my Docker guide to understand how you can follow the logs to check the start-up of the InfluxDB docker container. You may use Dozzle logs viewer for real-time logs viewing.

If all goes well, in a few minutes you should be to access InfluxDB using one of the URLs listed previously.

Influxdb Welcome Screen
Influxdb Welcome Screen

4. InfluxDB Setup

Access InfluxDB using 192.168.1.111:8086 (of course use your IP) and go through the initial setup.

You have to create a user, password, and organization, which can be anything to your liking.

You will also need to create a bucket (database) to store your data. This can also be anything (you can delete, create other buckets, etc. later).

Influxdb Inital Setup
Influxdb Inital Setup

After completing the above step, you will be shown an API password with superuser privileges. Save it in a safe location. You may not need it often, but when needed, you will have it.

Influxdb Api Token
Influxdb Api Token

For time series databases (buckets), I recommend creating custom API tokens with restricted privileges).

InfluxDB Initial Setup using Environmental Variables

You may also automatically perform the initial setup process using the following Docker environmental variables, as described in the docs:

  • DOCKER_INFLUXDB_INIT_MODE=setup
  • DOCKER_INFLUXDB_INIT_USERNAME=my-user
  • DOCKER_INFLUXDB_INIT_PASSWORD=my-password
  • DOCKER_INFLUXDB_INIT_ORG=my-org
  • DOCKER_INFLUXDB_INIT_BUCKET=my-bucket
  • DOCKER_INFLUXDB_INIT_RETENTION=1w
  • DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=my-super-secret-auth-token

Although not required, if you want to keep your InfluxDB docker-compose clean, remove the above variables after the first run and setup completion.

5. Accessing InfluxDB

Accessing InfluxDB web UI and database from within your home network should work fine (described above). But what if you want access to InfluxDB from outside your home network (or your server and client are in different locations)?

There are 2 things here: 1) being able to access InfluxDB web UI while not at home and 2) being able to connect to your database while not on the same network.

Port Fowarding 8086

The easiest and NOT RECOMMENDED way to do this is to forward port 8086 on your router/gateway to point to your InfluxDB server's (Docker host) IP address.

Accessing Web UI (only) Remotely

A secure and recommended way to access the InfluxDB web interface is to put it behind a reverse proxy. But this requires a domain name or a DDNS.

Nginx Proxy Manager is very simple to setup but not very flexible.

I use and recommend Traefik. You can read all about setting it up in my Docker Traefik guide or refer to my GitHub repo.

With a reverse proxy, you can access the InfluxDB web interface using a nicer URL (e.g. https://influxdb.example.com).

Secure Access using VPN

There are multiple ways to do this. It is better to cover those in separate guides.

  • VPN on Router: If your router allows a VPN connection, you can connect to it remotely and immediately have access to InfluxDB using the Docker host URL mentioned previously.
  • VPN Mesh Network: There are third-party services such as Tailscale and ZeroTier-One that offer free mesh network plans. I use ZeroTier to tie all my key machines together in a virtual network. My Docker host is part of this network. Therefore, from a remote machine, which is part of the ZeroTier network, I can use my Docker host's ZeroTier network IP address with InfluxDB port (8086). If you take this approach then you cannot use macvlan networking.

Another alternative is to set up your own Wireguard network. But this is a more advanced topic.

Other Posts in the Wireguard Series:

6. InfluxDB Grafana Dashboard Tutorials

FAQ

How to install InfluxDB using Docker?

InfluxDB can be installed using the docker run command or using the Docker Compose for InfluxDB specified in this guide. Docker compose is the recommended way.

How to install InfluxDB locally?

When InfluxDB is installed using Docker, it is installed locally on the Docker host, but isolated from the host operating system. Regardless, InfluxDB will function as if it is installed locally on the host system.

What is InfluxDB default username and password?

Unless username and password are set using Docker environmental variables, there are no default username and password for InfluxDB. They will have to be created using the web interface during the initial setup process.

How do I access InfluxDB?

InfluxDB listens on port 8086 on the system it is installed in. Therefore InfluxDB can be accessed using http://localhost:8086 on the system it is installed in or using http://IP-ADDRESS:8086 from a remote system.

What's Next After Setting Up InfluxDB on Docker

Before you can connect to InfluxDB from say Grafana, you will need the Influxdb data source (IP address and port), bucket (database) name, and token with proper access rights to bucket(s). You will also need the organization name that you set.

InfluxDB is a powerful time series database for sensor, IoT data, and other metrics. I use it to monitor my Proxmox server. An InfluxDB Grafana Docker-Compose tutorial on this is in the works. So stay tuned.

Installing InfluxDB natively on operating systems is not difficult. But Docker makes it much easier to install InfluxDB, and Docker Compose simplifies it even more. With the included InfluxDB Docker Compose and easy steps to install InfluxDB, you should be up and running in just about 5 minutes.

Be the 1 in 200,000. Help us sustain what we do.
34 / 150 by Dec 31, 2024
Join Us (starting from just $1.67/month)

Anand

Anand is a self-learned computer enthusiast, hopeless tinkerer (if it ain't broke, fix it), a part-time blogger, and a Scientist during the day. He has been blogging since 2010 on Linux, Ubuntu, Home/Media/File Servers, Smart Home Automation, and related HOW-TOs.