Create additional buckets on docker compose influx setup

Hello, im searching how to aproach my case.

I want to influx to setup specified user and create two adittional buckets in order to save telegraf data on docker start

I have this docker compose

version: "3"

services:

grafana:

image: grafana/grafana:latest

container_name: grafana

restart: always

ports:

  - '3000:3000'

volumes:

  - ./grafana-provisioning/:/etc/grafana/provisioning

depends_on:

  - influxdb

environment:

  - GF_SECURITY_ADMIN_USER=admin

  - GF_SECURITY_ADMIN_PASSWORD=admin

influxdb:

image: influxdb:2.0

volumes:

  - ./influxdbv2:/root/.influxdbv2

environment:

   # Use these same configurations parameters in your telegraf configuration, mytelegraf.conf.

  - DOCKER_INFLUXDB_INIT_MODE=setup

  - DOCKER_INFLUXDB_INIT_USERNAME=TrazastockUser

  - DOCKER_INFLUXDB_INIT_PASSWORD=14122004Hol@

  - DOCKER_INFLUXDB_INIT_ORG=ceit

  - DOCKER_INFLUXDB_INIT_BUCKET=data

  - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=kUERQvP1fV7Tra0oo1CbaRIsqHgixJS_qgp5H02zmXOq3dtU0s8O-CGCecPMoWMo1riv5hS3WsJHHr

ports:

  - "8086:8086"

influxdb_cli:

  image: influxdb:2.0

  links:

  - influxdb

  volumes:

  # Mount for influxdb data directory and configuration

  - ./influxdbv2:/root/.influxdbv2

  environment:

   # Use these same configurations parameters in your telegraf configuration, mytelegraf.conf

  entrypoint: ["./entrypoint.sh"]

  restart: on-failure:10

  depends_on:

  - influxdb

telegraf:

image: telegraf    

links:

  - influxdb

volumes:

 - ./particles.conf:/etc/telegraf/telegraf.conf:ro

 - ./Particles:/etc/telegraf/Particles

 - /var/run/docker.sock:/var/run/docker.sock:ro

environment:

 - DOCKER_INFLUXDB_INIT_ORG=organization

 - DOCKER_INFLUXDB_INIT_BUCKET=bucket1

 - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=kUERQvP1fV7Tra0oo1CbaRIsqHgixJS_qgp5H02zmXOq3dtU0s8O-CGCecPMoWMo1riv5hS3WsJHHr

depends_on:

  - influxdb_cli

telegraf1:

image: telegraf    

links:

  - influxdb

volumes:

 - ./meteorology.conf:/etc/telegraf/telegraf.conf:ro

 - ./Meterology:/etc/telegraf/Meterology

 - /var/run/docker.sock:/var/run/docker.sock:ro

environment:

 - DOCKER_INFLUXDB_INIT_ORG=organization

 - DOCKER_INFLUXDB_INIT_BUCKET=bucket2

 - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=kUERQvP1fV7Tra0oo1CbaRIsqHgixJS_qgp5H02zmXOq3dtU0s8O-CGCecPMoWMo1riv5hS3WsJHHr5OGPoDrA==

depends_on:

  - influxdb_cli

volumes:

 influxdb2:

when compose initializes influx starts and run setup succesfully but in the entrypoint script i want to initialize two adittional buckets to save telegraf data.

This is the entrypoint script :

image

but this script won`t execute and telegraf returns bucket not found

i’ll been searching for a while but i didn`t find any solution

thanks for the help

Hi, you can add influxdb-cli service to your docker compose file to create additional buckets with the following command:

I’m using InfluxDB 2.7.1

influxdb_cli:
    links:
      - influxdb
    image: quay.io/influxdb/influxdb:v2.0.4
    entrypoint: influx bucket create --skip-verify --name telegraf --retention 30d --org my-org --host http://influxdb:8086 --token my-token
    depends_on:
      - influxdb
    networks:
      influxdb: null

Output from influx-cli container after start up:

2023-07-10 19:06:30 ID                  Name            Retention       Organization ID
2023-07-10 19:06:30 8d6d7e371e32f372    telegraf        720h0m0s        b500c7ebce7e7a10

Cheers