Problems running via docker-compose

Hello - could you please review my docker-compose file, as I'm getting a ton of errors.

docker-compose file:

version: '2'

services:
    elasticsearch:
      container_name: elasticsearch
      restart: always
      image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
      ports:
        - "127.0.0.1:8200:9200"
        - "127.0.0.1:8300:9300"
      volumes:
        - /opt_docker/data/elasticsearch:/usr/share/elasticsearch/data
        - /opt_docker/log/elasticsearch:/usr/share/elasticsearch/logs
      env_file:
        - ./environment
      environment:
        - client_id=elasticsearch
        - MACHINE_NAME=${HOSTNAME}
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        - discovery.type=single-node
      ulimits:
        memlock:
          soft: -1
          hard: -1
      depends_on:
      mem_limit: 8192m

errors:

	[2018-09-03T23:13:59,324][INFO ][o.e.n.Node               ] [] initializing ...
	[2018-09-03T23:13:59,375][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
	org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: Failed to create node environment
		at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
		at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
		at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
	Caused by: java.lang.IllegalStateException: Failed to create node environment
		at org.elasticsearch.node.Node.<init>(Node.java:273) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.node.Node.<init>(Node.java:252) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.3.2.jar:6.3.2]
		... 6 more
	Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
		at sun.nio.fs.UnixException.translateToIOException(UnixException.java:90) ~[?:?]
		at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]
		at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[?:?]
		at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:385) ~[?:?]
		at java.nio.file.Files.createDirectory(Files.java:682) ~[?:?]
		at java.nio.file.Files.createAndCheckIsDirectory(Files.java:789) ~[?:?]
		at java.nio.file.Files.createDirectories(Files.java:775) ~[?:?]
		at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:203) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.node.Node.<init>(Node.java:270) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.node.Node.<init>(Node.java:252) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.3.2.jar:6.3.2]
		at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.3.2.jar:6.3.2]
		... 6 more

Most likely your volume is not writable from the container?

why wouldn't the volume be writable from the container?

I don't know. But

Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes

Seems to indicate that.

is there a standard fix? What pattern should one follow for pulling down the container, and then persisting the volume container? It seems like everyone that pulls down the container and tries to persist the data will run into this problem.

Did you check who is the owner of /opt_docker/data/elasticsearch dir?

it is owned by root, the elasticsearch user only exists in the docker container

But does Docker runs as root? I'm not super familiar with Docker though.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.