Deploy InfluxDB Container with Docker Compose

Introduction


InfluxDB is a high-performance, open-source, distributed, and scalable time-series database. It is designed to handle and store large volumes of time-stamped data, making it particularly well-suited for use cases that involve collecting, querying, and analyzing time-series data such as metrics, events, and sensor readings.

Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define an entire application stack, including services, networks, and volumes, in a single file called docker-compose.yml. With a single command, you can then spin up your entire application stack, simplifying the process of managing and deploying multi-container Docker applications.

Prerequisites

  • Up and running ubuntu 22.04 LTS machine.
  • Basic knowledge in linux commands.
  • Internet connectivity.
  • Docker and docker compose should installed on your machine.

To install Docker and docker compose on ubuntu 22.04 LTS, We can use the given link.

In this post, We will InfluxDB container using Docker Compose on Ubuntu 22.04 LTS Debian machine.

Step 1: Creating docker-compose.yml

To deploy InfluxDB using Docker Compose, you’ll need to create a docker-compose.yml file with the necessary configuration. Below is a basic example to get you started::

To create a separate directory for Prometheus InfluxDB’s docker-compose.yml file.

sudo mkdir InfluxDB && cd InfluxDB

To create a docker-compose.yml

sudo nano docker-compose.yml

Copy and paste the followings configuration.

version: '3'

services:
  influxdb:
    image: influxdb:latest
    container_name: influxdb
    ports:
      - "8086:8086"
    volumes:
      - influxdb-data:/var/lib/influxdb
    environment:
      - INFLUXDB_DB=mydb
      - INFLUXDB_ADMIN_USER=admin
      - INFLUXDB_ADMIN_PASSWORD=admin
      - INFLUXDB_USER=myuser
      - INFLUXDB_USER_PASSWORD=mypassword

volumes:
  influxdb-data:

This Docker Compose file:

  • Uses the official InfluxDB image from Docker Hub.
  • Maps port 8086 to the host machine, which is the default InfluxDB API port.
  • Mounts a volume named influxdb-data to persist InfluxDB data.
  • Sets environment variables for database creation (INFLUXDB_DB), admin credentials, and a regular user with its credentials.

Save the docker-compose.yml file.

Step 2: Deploy InfluxDB Container

In the directory where your docker-compose.yml file is located, run the following command to start the AInfluxDB container:

sudo docker-compose up -d

The -d flag runs the containers in the background, It will take few sec or mins to pull the image and deploy the Grafana.

Step 3: Validate the Container

To check the running containers launched by Docker Compose, you can use the following command:

sudo docker-compose ps

This command provides a summary of the status of each service defined in your docker-compose.yml file. It shows information such as the service name, container ID, status, ports, and names.

Step 4: Logging

Some time we need to also check the real time logs, So we can use the given commands.

sudo docker-compose logs -f influxdb

Step 5: Accessing

InfluxDB will be accessible at http://localhost:8086 or http://IPaddress:8086. You can use tools like InfluxDB’s web interface or command-line tools to interact with the database.

This basic setup provides a simple InfluxDB instance with a predefined database (mydb), an admin user (admin), and a regular user (myuser). Adjust the configuration, such as passwords and database names, based on your requirements.

Step 6: Destroying InfluxDB Container

We need to execute the given command to destroy the InfluxDB’s docker container under docker compose.

sudo docker compose down 

Conclusion

We have successfully deployed InfluxDB docker’s container using docker compose on ubuntu 22.04 LTS Debian machine, If you still have questions, please post them in the comments section below.

Author

Deploy InfluxDB Container with Docker Compose

Leave a Reply

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

Scroll to top