Elastic search docker container stops automatically

Hi Team,

I am trying to configure ELK stack in docker container. But the Elastisearch docker container exited automatically.

Please help me on this.

#here is my docker-compose file
version: '2'

services:

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
container_name: elasticsearch
volumes:
- ./esdata:/usr/share/elasticsearch/data
ports:
- "9200:9200"
- "9300:9300"
environment:
ES_JAVA_OPTS: "-Xmx256m -Xms256m"
networks:
- elk

logstash:
image: docker.elastic.co/logstash/logstash:7.2.0
container_name: logstash
volumes:
# - ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro
- ./logstash/pipeline:/usr/share/logstash/pipeline:ro
#- /var/log/GDPR/myapplication:/var/log/GDPR/myapplication:ro
ports:
- "5000:5000"
- "5044:5044"
environment:
LS_JAVA_OPTS: "-Xmx256m -Xms256m"
networks:
- elk
depends_on:
- elasticsearch
links:
- elasticsearch

kibana:
image: docker.elastic.co/kibana/kibana:7.2.0
container_name: kibana
#volumes:
# - ./kibana/config/:/usr/share/kibana/config:ro
environment:
ELASTICSERCH_URL: "http://elasticsearch:9200"
ports:
- "5601:5601"
networks:
- elk
depends_on:
- elasticsearch
links:
- elasticsearch

networks:
elk:
driver: bridge

#Here is docker-compose logs for elasticsearch service

]# docker-compose logs elasticsearch
Attaching to elasticsearch
elasticsearch | OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
elasticsearch | {"type": "server", "timestamp": "2019-07-24T16:54:55,519+0000", "level": "WARN", "component": "o.e.b.ElasticsearchUncaughtExceptionHandler", "cluster.name": "docker-cluster", "node.name": "8ddb32dd4527", "message": "uncaught exception in thread [main]" ,
elasticsearch | "stacktrace": ["org.elasticsearch.bootstrap.StartupException: ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes];",
elasticsearch | "at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "Caused by: org.elasticsearch.ElasticsearchException: failed to bind service",
elasticsearch | "at org.elasticsearch.node.Node.(Node.java:580) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.node.Node.(Node.java:251) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.bootstrap.Bootstrap$5.(Bootstrap.java:221) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:221) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "... 6 more",
elasticsearch | "Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes",
elasticsearch | "at sun.nio.fs.UnixException.translateToIOException(UnixException.java:90) ~[?:?]",
elasticsearch | "at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]",
elasticsearch | "at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[?:?]",
elasticsearch | "at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:389) ~[?:?]",
elasticsearch | "at java.nio.file.Files.createDirectory(Files.java:692) ~[?:?]",
elasticsearch | "at java.nio.file.Files.createAndCheckIsDirectory(Files.java:799) ~[?:?]",
elasticsearch | "at java.nio.file.Files.createDirectories(Files.java:785) ~[?:?]",
elasticsearch | "at org.elasticsearch.env.NodeEnvironment.lambda$new$0(NodeEnvironment.java:271) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.env.NodeEnvironment$NodeLock.(NodeEnvironment.java:208) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.env.NodeEnvironment.(NodeEnvironment.java:268) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.node.Node.(Node.java:271) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.node.Node.(Node.java:251) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.bootstrap.Bootstrap$5.(Bootstrap.java:221) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:221) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.2.0.jar:7.2.0]",
elasticsearch | "... 6 more"] }

Hi Team,

Can anyone help me on this.

Hi @soumya2,

The docker-compose.yml is a yaml file that care about the space can you format your message to check that there's no space or format problem somewhere?

according to your error message:

elasticsearch | {"type": "server", "timestamp": "2019-07-24T16:54:55,519+0000", "level": "WARN", "component": "o.e.b.ElasticsearchUncaughtExceptionHandler", "cluster.name": "docker-cluster", "node.name": "8ddb32dd4527", "message": "uncaught exception in thread [main]" ,

there's something wrong with cluster.name but you don't define it???

 version: '2.2'
 services:
   elasticsearch:
     build: ../services/elasticsearch/local/.
     container_name: elasticsearch_6.8.1
     environment:
       - cluster.name=docker-cluster
       - bootstrap.memory_lock=true
       - "ES_JAVA_OPTS=-Xms1G -Xmx1G"
       - discovery.type=single-node

In my composer I have the value in environment.

Also if you can consider go by step first make elastic running then add Logstash and if both are ok add Kibana. This way you can check and set the different configuration and options.
Need several builds before having the definitive configuration.
Last thing 256m maybe not enough, depend on your usage.