Logstash File Input sincedb_path vs. Docker Read‑Only Filesystem: Unresolved Path Resolution
0 reputation · 26 Oct 2022, 15:29 UTC
0 reputation · 26 Oct 2022, 15:29 UTC
Logstash’s File Input plugin uses sincedb_path to remember which lines of a file have already been processed. When a pipeline is launched locally, the plugin creates the sincedb file in the current working directory, which is usually writable. In a Docker or Kubernetes deployment, the working directory may be mounted read‑only or relocated, causing the sincedb file to be written to /tmp or not created at all. This leads to duplicate or missing events after a restart.
The documentation states that sincedb_path can be set to an absolute path, but it does not clarify how relative paths are resolved across operating systems or container runtimes, leaving the decision ambiguous.
Unresolved questions:
sincedb_path when running inside a container?sincedb_path to avoid duplicate events in a read‑only environment?33275 reputation · 27 Oct 2022, 03:06 UTC
1. What base directory does Logstash use to resolve a relative sincedb_path when running inside a container?
Logstash resolves a relative sincedb_path against the container’s current working directory (CWD). The CWD is set by the WORKDIR directive in the Dockerfile (defaulting to /usr/share/logstash) or by the -w flag passed to docker run.
2. How can we reliably configure sincedb_path to avoid duplicate events in a read‑only environment?
Use an absolute path that points to a writable volume mounted into the container. For example:
input {
file {
path => "/var/log/app/*.log"
sincedb_path => "/var/lib/logstash/sincedb"
}
}
Mount /var/lib/logstash from the host (e.g., docker run -v /opt/logstash-sincedb:/var/lib/logstash) and ensure the directory is owned by the logstash user (UID 1000 by default).
3. Does Logstash provide a configuration option to override the default relative path resolution?
No. The plugin does not expose a separate key for changing the base directory. The only supported method is to supply an absolute path.
/tmp or fails silently; this can lead to duplicate or missing events after restarts.docker exec <container> sh -c 'echo $PWD'
mkdir -p /opt/logstash-sincedb
chown 1000:1000 /opt/logstash-sincedb
docker run -d \
-v /opt/logstash-sincedb:/var/lib/logstash \
-v /var/log/app:/var/log/app \
--name logstash my-logstash-image
sincedb_path absolutely in the pipeline.docker exec <container> ls -l /var/lib/logstash/sincedb
docker exec <container> logstash -f /usr/share/logstash/pipeline.conf -v | grep sincedb
docker run -w /app), verify that the relative path still resolves to the intended directory.ls -l /var/lib/logstash should show UID 1000.If you are still observing duplicates after following the steps above, confirm whether the container’s WORKDIR is being overridden at runtime. The recommendation to use an absolute sincedb_path remains valid regardless of that detail.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.