title: Elasticsearch docker on travis fails with folder access denied
body: <p>I am having trouble using an Elasticsearch docker image on travis. </p>
  
  <p>Given this <code>docker-compose.yml</code> file:</p>
  
  <pre><code>version: '2'
  services:
    elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
      ports:
        - "9200:9200"
      environment:
        - "discovery.type=single-node"
        - "transport.host=127.0.0.1"
        - "xpack.security.enabled=false"
      volumes:
        - ./elasticsearch/data:/usr/share/elasticsearch/data
    kibana:
      image: docker.elastic.co/kibana/kibana:6.4.2
      ports:
        - "5601:5601"
      depends_on:
        - elasticsearch
      environment:
        - "ELASTICSEARCH_URL: http://elasticsearch:9200"
  </code></pre>
  
  <p>and the following <code>.travis.yml</code> file:</p>
  
  <pre><code>before_install:
  - docker-compose up -d
  - docker-compose logs -f &amp;
  - wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200
  [...more stuff here...]
  </code></pre>
  
  <p>The Elasticsearch engine fails to start with the following exception:</p>
  
  <pre><code>elasticsearch_1  | [2018-10-19T08:09:23,574][INFO ][o.e.n.Node               ] [] initializing ...
  elasticsearch_1  | [2018-10-19T08:09:23,627][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
  elasticsearch_1  | org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: Failed to create node environment
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  | Caused by: java.lang.IllegalStateException: Failed to create node environment
  elasticsearch_1  |  at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:277) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:256) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Bootstrap$5.&lt;init&gt;(Bootstrap.java:213) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  ... 6 more
  elasticsearch_1  | Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
  elasticsearch_1  |  at sun.nio.fs.UnixException.translateToIOException(UnixException.java:90) ~[?:?]
  elasticsearch_1  |  at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]
  elasticsearch_1  |  at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[?:?]
  elasticsearch_1  |  at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:385) ~[?:?]
  elasticsearch_1  |  at java.nio.file.Files.createDirectory(Files.java:682) ~[?:?]
  elasticsearch_1  |  at java.nio.file.Files.createAndCheckIsDirectory(Files.java:789) ~[?:?]
  elasticsearch_1  |  at java.nio.file.Files.createDirectories(Files.java:775) ~[?:?]
  elasticsearch_1  |  at org.elasticsearch.env.NodeEnvironment.&lt;init&gt;(NodeEnvironment.java:203) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:274) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:256) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Bootstrap$5.&lt;init&gt;(Bootstrap.java:213) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.2.jar:6.4.2]
  elasticsearch_1  |  ... 6 more
  </code></pre>
  
  <p>Note the <code>Caused by: java.nio.file.AccessDeniedException</code> above. The folder <code>./elasticsearch/data</code> exists and seems to be attributed to <code>travis:travis</code> as usual.</p>
  
  <p>I need help identifying the root cause here, and to find a solution that hopefully does not involve brute-forcing the permissions using <code>chown</code> or <code>chmod</code>, and that works on my local machine too (i.e. no hard-coded uids).</p>