Setting up and Running InfluxDB using Docker

In this tutorial, we will show you how to set up and run an InfluxDB server using Docker

InfluxDB Docker Compose

InfluxDB is a time series database that is incredibly useful for storing any data that you want to track over a period of time. For example, if you are pulling in data from a sensor, Influx is a great place to store it so you can graph changes over time.

One of the best ways to install and run the InfluxDB server is to utilize a Docker container. One key advantage Docker introduces is the ease of deployment. You don’t have to stress about incompatible operating system packages as long as your base system supports Docker.

Additionally, Docker makes updating to the latest version of InfluxDB as simple as running a couple of commands. It also makes the setup process super straightforward.

The official InfluxDB container we are using supports ARM systems, so you can follow this guide even if you are using a device like a Raspberry Pi.

How to Use Docker to Run InfluxDB

In the following sections, we will show you how to use Docker Compose to download and run InfluxDB.

We are using Docker Compose rather than straight Docker as it simplifies managing your containers.

Installing Docker

1. In this first section, we will use a quick method for installing the Docker runtime on our system. We will use Docker to run the InfluxDB container.

If you already have Docker installed, skip to step 4 of this tutorial. Alternatively, you can easily install Docker by using the command below.

curl -sSL https://get.docker.com | sh

2. Once the script above has finished installing the Docker runtime, you can add your current user to the “docker” group by running the command below.

The usermod command allows us to easily add a group to a user. In this case, we are using the “$USERenvironment variable, which holds the current user’s name.

sudo usermod -aG docker $USER

3. Any change to a user, such as adding a group, requires you to log out or restart your system.

If you are using the terminal, you can log out by running the command below.

logout

Alternatively, you can ensure the change propagates by restarting your system with the following command.

sudo reboot

Preparing your System for the InfluxDB Docker Container

4. Your next step is to use the mkdir command to create a directory where we will store the InfluxDB Docker Compose file and where it will store its data.

You can create a directory within the “/opt/” folder using the following command. The “-p” tag ensures the whole path will be generated.

sudo mkdir -p /opt/stacks/influxdb

5. With the directory created, you will want to change into it by using the cd command.

cd /opt/stacks/influxdb

Writing a Docker Compose File for InfluxDB

6. Now that we are within the InfluxDB directory we created, we can move on to writing a Compose file.

This Docker Compose file will be used to select and configure the InfluxDB container. By running the command below, we can begin writing this file using the nano text editor.

sudo nano compose.yaml

7. Within this compose file you will want to fill out the following lines.

You will need to replace a few placeholders within this file that will be used to configure the InfluxDB Docker container.

  • <ADMINUSER>: The first step is to specify the username that you want to use for your InfluxDB admin.
  • <ADMINPASSWORD>: Next, specify the password you will use to log in to your admin account.
  • <ORGANIZATION>: With InfluxDB, every user must belong to an organization. Multiple users can belong to an organization.
  • <BUCKET>: When you first set up InfluxDB, it requires an initial bucket. Assign a name for this initial bucket, which will be created when the container starts.
services:
  influxdb:
    image: influxdb:2
    container_name: influxdb
    restart: always
    ports:
      - '8086:8086'
    environment:
      DOCKER_INFLUXDB_INIT_MODE: setup
      DOCKER_INFLUXDB_INIT_USERNAME: <ADMINUSER>
      DOCKER_INFLUXDB_INIT_PASSWORD: <ADMINPASSWORD>
      DOCKER_INFLUXDB_INIT_ORG: <ORGANIZATION>
      DOCKER_INFLUXDB_INIT_BUCKET: <BUCKET>
    volumes:
      - ./data:/var/lib/influxdb2
      - ./config:/etc/influxdb2

8. Once you have finished writing the Compose file, you can save and quit by pressing CTRL + X, Y, and then ENTER.

Starting your InfluxDB Container

9. With the Compose file written, all we need to do to start the InfluxDB Docker Container is use the below command.

By including the “-d” option, Docker will detach from the terminal once it has downloaded and run InfluxDB.

docker compose up -d

Accessing the InfluxDB Web Interface

10. With the InfluxDB Docker container up and running, you will want to know how to access its web interface.

First, you will want to know the IP address of your machine. If you don’t know it, you can get your IP using the hostname command.

hostname -I

11. Within your favorite web browser, you will want to go to the following address.

Ensure you replace “<IPADDRESS>” with the IP of the machine you set up InfluxDB on.

http://<IPADDRESS>:8096

12. When you access the InfluxDB web interface you will be required to sign in to an account.

Type in the admin username and password you set when creating the Docker container (1.).

Once you are happy with the details you entered, click the “SIGN IN” button (2.).

Login to InfluxDB Web Interface

13. You have successfully got InfluxDB up and running using a Docker container.

You can now easily control the database through its web interface and start sending data to your buckets.

InfluxDB Running from within Docker Container

Updating the InfluxDB Docker Container

InfluxDB updates its software relatively often, which means an easier update process is crucial. This is where a key advantage to Docker comes in, as upgrading to the latest version is super simple, and you don’t have to worry about any operating system packages causing issues with new releases.

In the next couple of steps, we will show you how easy it is to update your InfluxDB Docker container.

1. Your first step is to change to the directory where we wrote the Compose file for InfluxDB.

Assuming you followed our original guide, you can simply use the command below.

cd /opt/stacks/influxdb

2. Once we are in the right place, we need to use Docker to pull the latest version of InfluxDB.

Getting Docker to download new images is as straightforward as using the command below.

docker compose pull

3. Even if the previous command downloaded a new update, it won’t automatically move your running container to it.

Luckily, if we use the same command we used to start the container in the first place, Docker will automatically detect the new version, stop the running container, and then start it again using the new image.

docker compose up -d

Conclusion

At this stage, you should have InfluxDB up and running within an easy-to-use Docker container.

Docker is a great solution for database servers like InfluxDB as it enables you to get it up and running in no time. Additionally, Docker also makes the update process super straightforward.

Please comment below if you have any questions about running this database server on your device.

If you found this tutorial helpful, please check out our many other Docker guides.

Leave a Reply

Your email address will not be published. Required fields are marked *