Persist Elasticsearch/Kibana Keystores with Docker

Goal: persist Elasticsearch/Kibana keystores across Docker sessions by mounting data directory

Common errors:

  1. Exception in thread "main" java.nio.file.FileSystemException: /usr/share/elasticsearch/config/elasticsearch.keystore.tmp -> /usr/share/elasticsearch/config/elasticsearch.keystore: Device or resource busy
  2. Likely root cause: java.io.IOException: Is a directory

Docker Context: Docker falls back to folder for file mounting when not overwriting existing file, so you need to mount the keystore's parent directory instead of the direct file. Verify claim via:

$ docker run -v /Users/me/elasticsearch-7.14.0/bin/elasticsearch.keystore:/usr/share/elasticsearch/config/elasticsearch.keystore elasticsearch:7.14.0 sh -c "cd config/elasticsearch.keystore && ls -la"
	total 4
	drwxr-xr-x 2 root          root   64 Aug  4 19:07 .
	drwxrwxr-x 1 elasticsearch root 4096 Aug  4 19:14 ..

Working Examples:

elasticsearch

$ docker run -it --rm -v /Users/me/elasticsearch/config:/usr/share/elasticsearch/config docker.elastic.co/elasticsearch/elasticsearch:7.14.0 bin/elasticsearch-keystore create
$ docker run -it --rm -v /Users/me/elasticsearch/config:/usr/share/elasticsearch/config docker.elastic.co/elasticsearch/elasticsearch:7.14.0 bin/elasticsearch-keystore add test_keystore_setting

kibana

$ docker run -it --rm -v /Users/me/kibana-7.14.0-darwin-x86_64/config:/usr/share/kibana/config -v /Users/me/kibana-7.14.0-darwin-x86_64/data:/usr/share/kibana/data docker.elastic.co/kibana/kibana:7.14.0 bin/kibana-keystore create
$ docker run -it --rm -v /Users/me/kibana-7.14.0-darwin-x86_64/config:/usr/share/kibana/config -v /Users/me/kibana-7.14.0-darwin-x86_64/data:/usr/share/kibana/data docker.elastic.co/kibana/kibana:7.14.0 bin/kibana-keystore add test_keystore_setting

Related doc PRs