title: Elasticsearch docker image with data persistence
body: <p>I am having an issue with data persistence on my Elasticsearch docker image on my linux AWS EC2 machine.</p>
  
  <p>I am launching the container like so:</p>
  
  <pre><code>docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 \
    -v $PWD/elasticsearch/data:/usr/share/elasticsearch/data \
    -e "discovery.type=single-node" \
    docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4
  </code></pre>
  
  <p>The issue is with the <code>-v $PWD/elasticsearch/data:/usr/share/elasticsearch/data</code> line. On Mac everything works correctly and I can persist my data after bringing down the container, but on the linux machine I get permission errors on the <code>/usr/share/elasticsearch/data</code> directory in the container.</p>
  
  <p>Error (line 3 is the critical part):</p>
  
  <pre><code>[2018-07-06T00:39:35,479][INFO ][o.e.n.Node               ] [] initializing ...
  [2018-07-06T00:39:35,503][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
  org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/share/elasticsearch/data/docker-cluster]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.2.4.jar:6.2.4]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.2.4.jar:6.2.4]
  Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/share/elasticsearch/data/docker-cluster]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
    at org.elasticsearch.env.NodeEnvironment.&lt;init&gt;(NodeEnvironment.java:244) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:264) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:246) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap$5.&lt;init&gt;(Bootstrap.java:213) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.4.jar:6.2.4]
    ... 6 more
  Caused by: java.io.IOException: failed to obtain lock on /usr/share/elasticsearch/data/nodes/0
    at org.elasticsearch.env.NodeEnvironment.&lt;init&gt;(NodeEnvironment.java:223) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:264) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:246) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap$5.&lt;init&gt;(Bootstrap.java:213) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.4.jar:6.2.4]
    ... 6 more
  Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes/0/node.lock
    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84) ~[?:?]
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) ~[?:?]
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) ~[?:?]
    at sun.nio.fs.UnixFileSystemProvider.newFileChannel(UnixFileSystemProvider.java:177) ~[?:?]
    at java.nio.channels.FileChannel.open(FileChannel.java:287) ~[?:1.8.0_161]
    at java.nio.channels.FileChannel.open(FileChannel.java:335) ~[?:1.8.0_161]
    at org.apache.lucene.store.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:125) ~[lucene-core-7.2.1.jar:7.2.1 b2b6438b37073bee1fca40374e85bf91aa457c0b - ubuntu - 2018-01-10 00:48:43]
    at org.apache.lucene.store.FSLockFactory.obtainLock(FSLockFactory.java:41) ~[lucene-core-7.2.1.jar:7.2.1 b2b6438b37073bee1fca40374e85bf91aa457c0b - ubuntu - 2018-01-10 00:48:43]
    at org.apache.lucene.store.BaseDirectory.obtainLock(BaseDirectory.java:45) ~[lucene-core-7.2.1.jar:7.2.1 b2b6438b37073bee1fca40374e85bf91aa457c0b - ubuntu - 2018-01-10 00:48:43]
    at org.elasticsearch.env.NodeEnvironment.&lt;init&gt;(NodeEnvironment.java:209) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:264) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:246) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap$5.&lt;init&gt;(Bootstrap.java:213) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.4.jar:6.2.4]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.4.jar:6.2.4]
    ... 6 more
  </code></pre>
  
  <p>What do I need to add to make this work on linux?</p>