IMD SolutionComputing LibraryShop main store

Troubleshooting

Why an InfluxDB container loses old data after restart

Edge computing and IIoT Published 5 min read

Short answer

An InfluxDB container that comes back empty after recreation was never writing to your mounted volumes. Its startup log names the real store: /root/.influxdbv2/influxd.bolt and /root/.influxdbv2/engine/data. Bind one host directory to /root/.influxdbv2 and confirm the recreated container opens that bolt file before trusting it with data.

On this page
  1. Read the startup log before touching mounts
  2. Why the three mounts saved nothing
  3. Example: three mounts against two runtime write paths
  4. Bind one host directory to /root/.influxdbv2
  5. Prove it across a second recreation
  6. What the Unauthorized lines do and do not mean
  7. Questions asked

Your InfluxDB container never had the old data to restore: it was writing into its own writable layer the whole time. The Compose file mounts /mnt/db, /mnt/influx and /etc/influxdb, but the startup log shows this build opens its bolt metadata at /root/.influxdbv2/influxd.bolt and its storage engine at /root/.influxdbv2/engine/data, so nothing it writes passes through a mount. Recreated, the container runs an initial migration on a brand-new store and looks empty. Bind one host directory to /root/.influxdbv2, confirm the next start opens that bolt file under the mount, and verify that a timestamp from before the restart is queryable. The startup log, not a remembered default path, decides where the mount goes.

Read the startup log before touching mounts #

Run docker logs influxdb and read three things before editing any mount. The log is the authority on where this exact build writes, and it settles a detail the image tag cannot: the Compose file pulls 2.0.0-rc while the running process reports version=2.0.0-rc.3 commit=f46a3bd91e.

  • msg="Resources opened" service=bolt path=/root/.influxdbv2/influxd.bolt — the bolt file holds the store's metadata: users, authorizations, buckets, organizations. If this path sits in the container's writable layer, none of that survives recreation.
  • msg="Using data dir" service=storage-engine path=/root/.influxdbv2/engine/data — the time-series files themselves live here.
  • Migration "initial migration" started (up) right after the welcome line — this migration runs when the bolt file just opened is brand new.

In the incident log the initial migration starts at 06:42:52.069082Z and completes at 06:42:52.120805Z: about 52 ms to create a store that was supposed to hold months of history. An initial migration on any start where real data should already exist is the diagnosis in one line — the bolt file being opened is not the one your writes went to.

Why the three mounts saved nothing #

A bind mount maps one host directory to one container-side destination and protects only files written through that destination. The Compose entry maps plausible names back onto themselves — /mnt/db/:/mnt/db/, /mnt/influx/:/mnt/influx/ and ./etc/influxdb/:/etc/influxdb/ — and no mount redirects an application by sharing a name: the engine went on writing under /root/.influxdbv2, inside the writable layer. docker compose down deleted that layer with the old container, and docker compose up initialized a new store in a new one.

Grafana and Telegraf kept their history through the same outage because their entries use named volumes at targets those images actually write: grafana-storage at /var/lib/grafana and telegraf-storage at /var/lib/telegraf. The same rule decides every container on the box, and the same miss bites other plant software — a guide to Ignition Docker modes that bind config/ rather than nested resource mounts makes the identical point for a SCADA container.

Example: three mounts against two runtime write paths #

Inputs, each from the incident itself. The Compose file declares 3 container-side mount destinations: /mnt/db, /mnt/influx and /etc/influxdb. The container's startup log names 2 active write paths: /root/.influxdbv2/influxd.bolt and /root/.influxdbv2/engine/data.

Rule in words. A write survives recreation only when its path lies at or beneath a mount destination; every other path lives in the container's writable layer, which docker compose down discards.

Arithmetic. Checking 3 destinations against 2 write paths gives 3 × 2 = 6 comparisons. Neither write path begins with /mnt/db, /mnt/influx or /etc/influxdb, so all 6 miss. Persisted coverage is 0 of 2 paths, and the unprotected remainder is 2 − 0 = 2 paths — the whole active store.

Result. 0 of 2 write paths persisted: every byte of metadata and time-series data sat in the layer that removal destroys, which is why the next start ran a full initial migration on an empty bolt.

Decision. Coverage must read 2 of 2 before the stack is trusted with data again. One mount whose container-side target is the parent of both paths, /root/.influxdbv2, covers them both at once — that is the fix below.

Bind one host directory to /root/.influxdbv2 #

  1. Copy out what is still recoverable. If the current container still holds history you need, copy it from its writable layer before removing anything; once the container is deleted, that layer and every file in it are gone, and this step is the only thing that can bring lost points back.
  2. Stop the stack so the engine closes its bolt and data files cleanly.
  3. Bind the host directory to the container path the log named. The host-side name is arbitrary; the container-side target decides everything. Reusing the directory already provisioned:
  influxdb:
    image: quay.io/influxdb/influxdb:2.0.0-rc
    container_name: influxdb
    restart: always
    ports:
      - 8086:8086
    networks:
      - analytics
    volumes:
      - /mnt/influx/:/root/.influxdbv2
      - ./etc/influxdb/:/etc/influxdb/

Keep the /etc/influxdb mount only if the deployment reads that configuration; it neither caused nor prevented the loss, because the runtime wrote none of its store there.

  1. Recreate and read the log again. The wanted pattern is msg="Resources opened" service=bolt path=/root/.influxdbv2/influxd.bolt followed by no Migration "initial migration" block.
  2. Re-create authorizations only for a genuinely new store. If the old layer is already gone, the new bolt holds no users or tokens, so run the image's documented setup once and issue fresh credentials to Telegraf and any dashboard clients. If the original bolt loaded, its original authorizations returned with it and nothing needs re-creating.

Prove it across a second recreation #

A single healthy start after the fix proves less than you need. Recreate the stack once more and check three distinct things in order: the process listens again with no error before it; no initial migration runs; and a query returns a known tag, value and timestamp from before the outage. A confirmed old point is the only evidence the store persisted — new writes arriving on their own are not.

Those new points do prove the HTTP write path, and that path's own setup is covered step by step in how to store MQTT messages in InfluxDB with Telegraf. If the recreated container refuses connections outright, the fault sits in service names or ports rather than storage, and Telegraf cannot reach an InfluxDB container by its name walks that diagnosis.

What the Unauthorized lines do and do not mean #

The incident log reaches its HTTP listening line before the first msg=Unauthorized error="authorization not found", so the service started cleanly; this is not a crash loop. Those entries are requests carrying a token that does not exist in the bolt metadata the container opened — on the fresh store created by the mismatched mounts there were no tokens at all, so every authenticated request failed. Fix the mount before touching credentials: the error follows the store that loaded, not the clients sending the requests.

Questions asked

Does the same fix apply to newer InfluxDB containers?

The fix is identical, mount the directory the startup log names, but the paths move between releases. An InfluxDB 3 Core container persists its data at /var/lib/influxdb3/data and listens on port 8181 rather than 8086, and a package install of InfluxDB OSS 2 keeps its bolt file at /var/lib/influxdb/influxd.bolt with the engine at /var/lib/influxdb/engine. Never carry a path between versions from memory; read the welcome and Resources opened lines of each build.

How do I tell a restored bolt file from a fresh one in the log?

A fresh bolt runs its initial migration followed by a sequence of index and bucket migrations immediately after the welcome line, and in this incident the whole block finished in milliseconds. A restored bolt opens and starts the engine without that migration block. If the migration lines appear on a start where data should already exist, the bolt being opened is not the one your writes went to, and the mount above it is still wrong.

Can a named volume replace the host directory bind mount?

Yes, as long as its container-side target is the directory the log names. Named volumes are what kept Grafana and Telegraf alive in the same stack. A bind mount suits this repair because the history already sits in a host directory, while a named volume suits a first deployment where the store starts empty and Docker manages the location on disk.

Can I relocate the store paths through configuration instead?

Yes, for the configuration file: the documented INFLUXDB_CONFIG_PATH environment variable points the process at a config file of your choosing, and that file can set the bolt and storage-engine locations. If you relocate them, the mount must cover the config file and every relocated directory, and the startup log must show each active path beneath a mount. One bind mount over the default directory stays simpler and leaves fewer paths to verify.

Keep reading

  • Troubleshooting

    Telegraf MQTT consumer connects but writes no data to InfluxDB

    An empty 0 / 10000 output buffer with both the MQTT and InfluxDB connections up means no metrics are reaching Telegraf's parser. Prove live delivery with a second subscriber on a different client ID before touching parser or buffer settings: the two startup connections are independent events, and with qos = 0 and a non-persistent session, traffic published while Telegraf is offline is unrecoverable.

    Edge computing and IIoT

  • Explainer

    Can plant historian software run in Docker containers

    The processes will start, but historian services hold retained state and are not documented to communicate statelessly, so a started container proves nothing about collection, calculations, events, or queries surviving replacement. Keep the working deployment in production and evaluate containers only in an isolated test, with a volume mapped for every path that holds data or configuration, passing a counted query across a restart, a recreate, and a host move.

    Edge computing and IIoT

  • Troubleshooting

    Fix InfluxDB database is locked on a network share

    The mounted share is the first suspect: InfluxDB 2.5.1 opens its bolt file on the share, then fails SQL migrations with database is locked because SQLite file locking is not dependable on NFS or SMB. Stop every process that can reach the paths, confirm the active bolt-path and engine-path, prove the same configuration on local storage, then keep the engine local and use the share only for backups.

    Edge computing and IIoT

Why Tier 2 historian replication loses the asset hierarchy view