influxdata / influxdata-docker

Official docker images for the influxdata stack
327 stars 248 forks source link

Why retention policy environment variable doesn't work? #580

Open agn-7 opened 2 years ago

agn-7 commented 2 years ago

I use influxdb v1.7.11 in a docker container. I read there is an env var in hub.docker influxdb description in order to set a retention policy on a database. However, it doesn't work!

DOCKER_INFLUXDB_INIT_RETENTION: The duration the system's initial bucket should retain data. If not set, the initial bucket will retain data forever.

Here's a piece of my docker-compose.yml:

  influxdb:
    image: influxdb:1.7.11
    ports:
      - "8086:8086"
    environment:
      - INFLUXDB_DB=metrics
      - INFLUXDB_USER=root
      - INFLUXDB_USER_PASSWORD=root
      - INFLUXDB_RETENTION_ENABLED=true
      - INFLUXDB_INIT_RETENTION=2h
      - DOCKER_INFLUXDB_INIT_RETENTION=2h
    volumes:
      - ./influxdb:/var/lib/influxdb
chc69 commented 2 years ago

Hi @Hipska

I have tested with Docker influxdb:2.2.0-alpine container with env variable DOCKER_INFLUXDB_INIT_RETENTION and got a similar issue.

The bucket always is infinite no matter what retention I set.

image

Is this a correct way to define retention with the official Influxdb container?

I also try to update the retention of an existing bucket with CLI. It seems CLI can assign the retention of the bucket.

image

After applying retention, I expect to see the influxdb clean older data, but all 4 days' data still remain there. Should I try to apply the new retention policy?

-- Update

I think I figure out the problem. The root cause is the initial retention settings are always in /etc/influxdb2 which is mounted to a folder of the host. Every time I recreate a container, it always refers to the existing and old config which's retention is infinite. Now I can create a container with any retention policy that I want after cleaning up the volume (i.e. /etc/influxdb2). FYR.

regnaio commented 5 months ago

-- Update

I think I figure out the problem. The root cause is the initial retention settings are always in /etc/influxdb2 which is mounted to a folder of the host. Every time I recreate a container, it always refers to the existing and old config which's retention is infinite. Now I can create a container with any retention policy that I want after cleaning up the volume (i.e. /etc/influxdb2). FYR.

@chc69 , can you please elaborate on this? /etc/influxdb2/ is empty by default on influxdb:2.7.5