8

I am running a Ruby on Rails application with a PostgreSQL database and an ElasticSearch server. I have these in separate Docker containers that work together in a network using Docker Compose and it is hosted on a Digital Ocean droplet (Ubuntu 20.04.1 LTS) where I am signed in as root. For reference, here are the containers listed using the command 'docker-compose ps':

          Name                         Command               State    Ports
---------------------------------------------------------------------------
database                    docker-entrypoint.sh postgres    Exit 0
myApp_elasticsearch_1   /tini -- /usr/local/bin/do ...   Exit 1
myApp_web_1             entrypoint.sh bash -c rm - ...   Exit 1

When I use the command:

docker-compose up

the application and database are operating as normal however the ElasticSearch server experiences errors and stops running. The most relevant part of the output appears to be:

ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes];
Likely root cause: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes

I have looked at similar answers for this error and it appears to be something related to the linux file system and user access permissions however I am not sure how to resolve this as I lack experience with linux file systems and user permissions.

This answer Using Persistent Host Volume for ElasticSearch with Docker-Compose seems to be the most similar however I'm still not sure how to apply this to my problem.

Appreciate any help.

My docker-compose.yml file is below:

version: "3.8"   
services:
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - bundle-volume:/usr/local/bundle
    ports:
      - "3000:3000"
    depends_on:
      - database
      - elasticsearch
    environment:
      RAILS_ENV: development
      DATABASE_NAME: myApp_development
      DATABASE_USER: postgres
      DATABASE_PASSWORD: **********
      POSTGRES_PASSWORD: **********
      DATABASE_HOST: database
      ELASTICSEARCH_URL: http://elasticsearch:9200

  database:
    image: postgres:12.3
    container_name: database
    volumes:
      - db_volume:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "5432:5432"
    environment: 
      DATABASE_PASSWORD: **********
      POSTGRES_PASSWORD: **********
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
    volumes:
      - ./docker_data/elasticsearch/data:/usr/share/elasticsearch/data
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.type=single-node
    ports:
      - 9200:9200
    ulimits:
      memlock:
        soft: -1
        hard: -1
volumes:
  bundle-volume:
  db_volume:
  data:

My Dockerfile is below:

FROM ruby:2.6.6-buster

RUN apt-get update -qq && \
    apt-get install -y curl \
    build-essential \
    libpq-dev \
    postgresql \
    postgresql-contrib \
    postgresql-client

RUN mkdir /myApp
RUN mkdir -p /usr/local/nvm
WORKDIR /myApp

RUN curl -sL https://deb.nodesource.com/setup_15.x | bash -
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v

COPY Gemfile Gemfile.lock package.json yarn.lock ./

RUN gem install bundler && bundle update --bundler && bundle install
RUN npm install -g yarn && yarn install --check-files

COPY . /myApp

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]

Full ElasticSearch response including the errors displayed below for reference.

elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:02,394Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "version[7.9.3], pid[6], build[default/docker/c4138e51121ef06a6404866cddc601906fe5c868/2020-10-16T10:36:16.141335Z], OS[Linux/5.4.0-52-generic/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/15/15+36-1562]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:02,400Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "JVM home [/usr/share/elasticsearch/jdk]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:02,401Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "JVM arguments [-Xshare:auto, -Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -XX:+ShowCodeDetailsInExceptionMessages, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dio.netty.allocator.numDirectArenas=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.locale.providers=SPI,COMPAT, -Xms1g, -Xmx1g, -XX:+UseG1GC, -XX:G1ReservePercent=25, -XX:InitiatingHeapOccupancyPercent=30, -Djava.io.tmpdir=/tmp/elasticsearch-15197622989873108878, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Des.cgroups.hierarchy.override=/, -Xms512m, -Xmx512m, -XX:MaxDirectMemorySize=268435456, -Des.path.home=/usr/share/elasticsearch, -Des.path.conf=/usr/share/elasticsearch/config, -Des.distribution.flavor=default, -Des.distribution.type=docker, -Des.bundled_jdk=true]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,138Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [aggs-matrix-stats]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,138Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [analysis-common]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,140Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [constant-keyword]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,140Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [flattened]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,141Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [frozen-indices]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,142Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [ingest-common]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,142Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [ingest-geoip]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,143Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [ingest-user-agent]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,143Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [kibana]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,145Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [lang-expression]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,147Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [lang-mustache]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,148Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [lang-painless]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,148Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [mapper-extras]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,149Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [parent-join]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,149Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [percolator]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,150Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [rank-eval]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,150Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [reindex]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,151Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [repository-url]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,152Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [search-business-rules]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,152Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [searchable-snapshots]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,153Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [spatial]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,153Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [tasks]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,154Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [transform]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,155Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [transport-netty4]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,155Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [vectors]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,156Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [wildcard]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,156Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-analytics]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,156Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-async]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,157Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-async-search]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,157Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-autoscaling]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,158Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-ccr]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,158Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-core]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,159Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-data-streams]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,159Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-deprecation]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,159Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-enrich]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,160Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-eql]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,160Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-graph]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,161Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-identity-provider]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,161Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-ilm]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,162Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-logstash]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,162Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-ml]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,163Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-monitoring]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,164Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-ql]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,164Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-rollup]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,164Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-security]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,165Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-sql]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,165Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-stack]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,166Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-voting-only-node]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,166Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "loaded module [x-pack-watcher]" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,167Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "no plugins loaded" }
elasticsearch_1  | {"type": "server", "timestamp": "2020-12-14T19:38:05,281Z", "level": "ERROR", "component": "o.e.b.ElasticsearchUncaughtExceptionHandler", "cluster.name": "docker-cluster", "node.name": "e33ecad0776c", "message": "uncaught exception in thread [main]",
elasticsearch_1  | "stacktrace": ["org.elasticsearch.bootstrap.StartupException: ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes];",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:174) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127) ~[elasticsearch-cli-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "Caused by: org.elasticsearch.ElasticsearchException: failed to bind service",
elasticsearch_1  | "at org.elasticsearch.node.Node.<init>(Node.java:695) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.node.Node.<init>(Node.java:277) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:227) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:227) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.9.3.jar:7.9.3]",
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:106) ~[?:?]",
elasticsearch_1  | "at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]",
elasticsearch_1  | "at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:388) ~[?:?]",
elasticsearch_1  | "at java.nio.file.Files.createDirectory(Files.java:694) ~[?:?]",
elasticsearch_1  | "at java.nio.file.Files.createAndCheckIsDirectory(Files.java:801) ~[?:?]",
elasticsearch_1  | "at java.nio.file.Files.createDirectories(Files.java:787) ~[?:?]",
elasticsearch_1  | "at org.elasticsearch.env.NodeEnvironment.lambda$new$0(NodeEnvironment.java:274) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:211) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:271) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.node.Node.<init>(Node.java:344) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.node.Node.<init>(Node.java:277) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:227) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:227) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.9.3.jar:7.9.3]",
elasticsearch_1  | "... 6 more"] }
elasticsearch_1  | uncaught exception in thread [main]
elasticsearch_1  | ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes];
elasticsearch_1  | Likely root cause: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
elasticsearch_1  |      at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
elasticsearch_1  |      at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
elasticsearch_1  |      at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
elasticsearch_1  |      at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:388)
elasticsearch_1  |      at java.base/java.nio.file.Files.createDirectory(Files.java:694)
elasticsearch_1  |      at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:801)
elasticsearch_1  |      at java.base/java.nio.file.Files.createDirectories(Files.java:787)
elasticsearch_1  |      at org.elasticsearch.env.NodeEnvironment.lambda$new$0(NodeEnvironment.java:274)
elasticsearch_1  |      at org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:211)
elasticsearch_1  |      at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:271)
elasticsearch_1  |      at org.elasticsearch.node.Node.<init>(Node.java:344)
elasticsearch_1  |      at org.elasticsearch.node.Node.<init>(Node.java:277)
elasticsearch_1  |      at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:227)
elasticsearch_1  |      at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:227)
elasticsearch_1  |      at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393)
elasticsearch_1  |      at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
elasticsearch_1  |      at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
elasticsearch_1  |      at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
elasticsearch_1  |      at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
elasticsearch_1  |      at org.elasticsearch.cli.Command.main(Command.java:90)
elasticsearch_1  |      at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
elasticsearch_1  |      at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
elasticsearch_1  | For complete error details, refer to the log at /usr/share/elasticsearch/logs/docker-cluster.log
myApp_elasticsearch_1 exited with code 1

2 Answers 2

24

The solution to this error is to use the below command in the application's main directory within the docker container:

sudo chown -R 1000:root docker_data

This provides the required access to the path '/usr/share/elasticsearch/data/nodes'

Sign up to request clarification or add additional context in comments.

3 Comments

how does this command get added to the docker-compose file? How do you integrate this in to your setup?
@StealthRabbi I haven't figured this out yet but it would be great to know. There is a suggestion below but I couldn't get it to work with my configuration. Let me know if you are posting this as a separate question.
In case if your docker container doesn't have sudo available -- the command I've used was sudo docker exec -u 0 <container_id> chown 1000:1000 /usr/share/opensearch/data.
-2
version: "3.5"
services:

  permissions:
    build: .
    command:
      - sudo chown -R 1000:1000 /usr/share/elasticsearch/data

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
    ports:
      - "9200:9200"
    environment:
      - "discovery.type=single-node"
    volumes:
      - ./elasticsearch/data:/usr/share/elasticsearch/data:rw
    depends_on:
      - permissions

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.