title: How to persist Zookeeper data in a docker setup via a volume?
body: <p>So, I am setting up Zookeeper in my local environment on docker using the <a href="https://hub.docker.com/_/zookeeper/" rel="nofollow noreferrer">official docker image</a>. Now, what I want with this Zookeeper setup is to be able to persist the nodes and their values by mounting the Zookeeper data directory as a volume inside my container.</p>
  
  <p>This is straightforward, but what's confusing me is that Zookeeper's data directory inside the container is at <code>/data</code> while the datalog directory is at <code>/datalog</code>. Ideally, I would expect Zookeeper to persist the nodes and values inside the data folder as well in addition to the datalog directory. However, I find that while the datalog directory has the data in <code>log.*</code> files, the data directory does not have any data related to the test nodes that I created.</p>
  
  <pre><code>bash-4.4# pwd
  /datalog/version-2
  bash-4.4# ls
  log.1  log.3  log.5  log.8
  
  
  bash-4.4# pwd
  /data/version-2
  bash-4.4# ls
  bash-4.4# 
  </code></pre>
  
  <p>My goal is achieved with this Zookeeper service in my <code>docker-compose.yml</code> -</p>
  
  <pre><code>volumes:
    - zkdata:/datalog
  </code></pre>
  
  <p>but this seems counter-intuitive that I am mounting the transaction logs directory instead of the actual data directory. How and where does Zookeeper actually persist the node data and how can I correctly mount it as a volume in my docker container?</p>
  
  <p>I can actually set the <code>ZOO_DATA_LOG_DIR</code> environmental variable to <code>/data</code> and mount that as a docker volume, but my question is really about why the Zookeeper data is empty while the datalog directory isn't.</p>