title: Elastic search AccessDeniedException[/usr/share/elasticsearch/data/nodes/0] -- Access denied error
body: <p>I am trying to use nfs mount as my elasticsearch data directory, earlier I was using host storage.
  But when I am trying to up my container, I am facing below mentioned error :</p>
  <pre><code> ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes/0];
  es02    | Likely root cause: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes/0
  es02    |   at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
  es02    |   at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
  es02    |   at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
  es02    |   at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:388)
  es02    |   at java.base/java.nio.file.Files.createDirectory(Files.java:694)
  es02    |   at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:801)
  es02    |   at java.base/java.nio.file.Files.createDirectories(Files.java:787)
  es02    |   at org.elasticsearch.env.NodeEnvironment.lambda$new$0(NodeEnvironment.java:275)
  es02    |   at org.elasticsearch.env.NodeEnvironment$NodeLock.&lt;init&gt;(NodeEnvironment.java:212)
  es02    |   at org.elasticsearch.env.NodeEnvironment.&lt;init&gt;(NodeEnvironment.java:272)
  es02    |   at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:362)
  es02    |   at org.elasticsearch.node.Node.&lt;init&gt;(Node.java:289)
  
  </code></pre>
  <p>I am using docker-compose for the same earlier my cluster was working fine,when i was using host storage but when i tried to switch to NFS storage i am facing above mentioned error.
  Below is my docker-compose file:</p>
  <pre><code>version: '3.3'
  volumes:
    data:
      driver: local
      driver_opts:
         type: nfs
         device: &quot;:/data1/elasticsearch_data&quot;
         o: addr=10.10.15.46,rw
  #volumes:
  #  repo:
  #    driver: local
  #    driver_opts:
  #       type: none
  #       device: /apm_backup
  #       o: bind
  #
  services:
    es02:
      image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
      container_name: es02
      volumes:
        - data:/usr/share/elasticsearch/data
  #      - ./unicast_hosts.txt:/usr/share/elasticsearch/config/unicast_hosts.txt
      environment:
        - node.name=es02
        - node.master=true
        - node.data=true
        - cluster.name=apm-docker-cluster
        - discovery.seed_hosts=es01
  #      - discovery.seed_providers=file
        - cluster.initial_master_nodes=es01,es02
        - bootstrap.memory_lock=true
        - &quot;ES_JAVA_OPTS=-Xms10g -Xmx10g&quot;
        - XPACK_SECURITY_ENABLED=false
  #      - path.repo=/apm_backup
  #    command: [&quot;elasticsearch&quot;, &quot;-Elogger.level=DEBUG&quot;]
      ulimits:
        memlock:
          soft: -1
          hard: -1
        nofile:
          soft: 65536
          hard: 65536
      restart: &quot;unless-stopped&quot;
      logging:
        driver: 'json-file'
        options:
            max-size: '2m'
            max-file: '5'
      ports:
        - 9200:9200
        - 9300:9300
      extra_hosts:
        - &quot;es01:10.10.26.27&quot;
        - &quot;es02:10.10.26.111&quot;
        - &quot;es03:10.10.26.111&quot;
      network_mode: &quot;host&quot;
      labels:
        org.label-schema.group: &quot;APM-monitoring&quot;
      healthcheck:
        test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;--write-out&quot;, &quot;'HTTP %{http_code}'&quot;, &quot;--silent&quot;, &quot;--output&quot;, &quot;/dev/null&quot;, &quot;http://es02:9200/&quot;]
        retries: 10
        interval: 10s
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/2jD5Q.png" rel="nofollow noreferrer">This is my directory permission and location</a></p>
  <p>What I have tried till now:</p>
  <p>chown 1000:1000 elasticsearch_data (1000 uid of vimzy user mentioned in photo).</p>
  <p>I have tried <em>priviliged=true</em> in docker-compose.
  and apart from this tried multiple ways to counter permission denied issue.</p>
  <p>Any help...</p>