Does InfluxDB's Docker init mode skip setup when the volume already has data?
0 reputation · 16 Apr 2023, 02:27 UTC
0 reputation · 16 Apr 2023, 02:27 UTC
I want repeatable integration tests against InfluxDB OSS in Docker (assuming the 2.7.x image line) where the container is provisioned automatically, without production credentials, and can be torn down and restarted against a persistent volume between test runs.
The image supports DOCKER_INFLUXDB_INIT_MODE=setup with the related DOCKER_INFLUXDB_INIT_* variables, and the /api/v2/setup endpoint offers a programmatic alternative. What is unclear is what exactly tells the init path that setup has already happened: the presence of the bolt file, the engine directory, or something else. If a second setup attempt runs, it is not obvious whether it fails cleanly, silently succeeds, or creates an additional operator token alongside the one pre-seeded via DOCKER_INFLUXDB_INIT_ADMIN_TOKEN. Since /api/v2/setup is unauthenticated, I would also like to understand the risk of leaving it reachable in a shared CI network.
/api/v2/setup is called again on an initialized instance, what status and token behavior should I expect?/health or /api/v2/buckets before invoking setup the recommended idempotency pattern, or is there a supported built-in one?32775 reputation · 16 Apr 2023, 06:23 UTC
Yes, the InfluxDB 2.7.x Docker image skips the DOCKER_INFLUXDB_INIT_MODE=setup process if it detects an existing database in the mounted volume. This mechanism is designed to prevent overwriting user data or regenerating administrative credentials during container restarts.
The entrypoint script checks for the existence of specific metadata within the data directory (typically /var/lib/influxdb). Specifically, it looks for the internal BoltDB file and the storage engine directory structure. If these are present, the script assumes the instance has already been initialized and exits the setup logic immediately, ignoring all DOCKER_INFLUXDB_INIT_* environment variables.
If you attempt to call the /api/v2/setup endpoint programmatically on an instance that is already initialized, the behavior is as follows:
400 Bad Request.For repeatable integration tests where you use persistent volumes between runs, relying solely on the container's init mode can be brittle if tests fail midway. Instead, use the following idempotency pattern:
/health endpoint to return success.GET request to /api/v2/buckets using your pre-seeded or environment-defined admin token.200 OK, the instance is ready; skip the setup step.401 Unauthorized or 404, invoke your /api/v2/setup logic.The /api/v2/setup endpoint is unauthenticated to allow for first-run configuration. In a shared CI network, this is a security risk as any entity with network access could potentially initialize an empty-DB instance. It is recommended to ensure the container is only exposed to internal CI networks or protected by a firewall once the setup is complete.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.