Installing and Setting Up InfluxDB with Docker



InfluxDB Setup Using Docker

This guide walks you through setting up InfluxDB using Docker. The setup includes creating volumes, running the Docker container with the necessary environment variables, and accessing the InfluxDB UI.

Step 1. Create Volumes

First, create the required volumes to store data and configuration files for InfluxDB.

docker volume create influxdb2-data

docker volume create influxdb2-config

The above 2 commands being ran in an Admin level Command Prompt window.

Step 2. Run the Docker Container

Run the Docker container with mounted volumes, port mapping, and initial setup options. The command includes all necessary flags and environment variables to configure InfluxDB with an initial username, password, organization, and bucket.

For simplicity, run the command in a single line to avoid any formatting issues:

docker run -d --name influxdb2 --publish 8086:8086 --mount type=volume,source=influxdb2-data,target=/var/lib/influxdb2 --mount type=volume,source=influxdb2-config,target=/etc/influxdb2 --env DOCKER_INFLUXDB_INIT_MODE=setup --env DOCKER_INFLUXDB_INIT_USERNAME=ielabs --env DOCKER_INFLUXDB_INIT_PASSWORD=admin123 --env DOCKER_INFLUXDB_INIT_ORG=purdue_gatewaylabs --env DOCKER_INFLUXDB_INIT_BUCKET=gateway_bucket influxdb:2

The above command being ran in an Admin level Command Prompt window.

Explanation of Additional Flags

  • --publish 8086:8086: Maps port 8086 of the host to port 8086 of the container, allowing you to access InfluxDB through http://localhost:8086.

  • --mount type=volume,source=influxdb2-data,target=/var/lib/influxdb2: Mounts the data volume.

  • --mount type=volume,source=influxdb2-config,target=/etc/influxdb2: Mounts the configuration volume.

  • --env DOCKER_INFLUXDB_INIT_MODE=setup: Specifies that the container should run the initial setup mode.

  • --env DOCKER_INFLUXDB_INIT_USERNAME=ielabs: Sets the initial admin username.

  • --env DOCKER_INFLUXDB_INIT_PASSWORD=admin123: Sets the initial admin password.

  • --env DOCKER_INFLUXDB_INIT_ORG=purdue_gatewaylabs: Sets the initial organization name.

  • --env DOCKER_INFLUXDB_INIT_BUCKET=gateway_bucket: Sets the initial bucket name.

Additional Notes

  • Ensure you replace the username, password, organization, and bucket values with those that match your actual setup requirements.

  • The --publish 8086:8086 flag is crucial for accessing the InfluxDB instance from outside the container.

Step 3. Verify the InfluxDB Container

Once the container is running, verify that the InfluxDB container is running successfully:

A view of the Docker containers displayed in Docker Desktop with the newly created container shown.

Step 4. Access InfluxDB UI

If the container is running successfully, you can view the InfluxDB UI at http://localhost:8086. Log in with the username and password that you set during the initial setup.

By following these steps, you will have an InfluxDB instance running via Docker, ready for integration into your projects.

InfluxDB Configuration

Create an API token

To use InfluxDB with other applications, such as Node-RED, you need to create an API Token. Follow these steps to manage and create tokens in the InfluxDB interfac.

Manage Tokens in the InfluxDB UI

  • Open the InfluxDB UI and navigate to the API Tokens management page.

  • In the navigation menu on the left, select Data (Load Data) > API Tokens.

Create a Token in the InfluxDB UI

  • From the API Tokens management page, click Generate and select a token type (Read/Write Token or All Access API Token).

  • In the window that appears, enter a description for your token in the Description field. For example, you can name it "Node-RED" since we will use it in Node-RED.

  • Make sure to save the token, you won't be able to see it again!

  • If generating a read/write token:

    • Search for and select buckets to read from in the Read pane.

    • Search for and select buckets to write to in the Write pane.

  • Click Save.

By following these steps, you will create an API token that can be used to authenticate and interact with your InfluxDB instance from other applications.