I am trying to run an ElasticSearch container, on a newly-created VM with Docker 1.12.5 installed, but meet a Permission Denied
exception. What puzzles me is that everything runs fine in an older VM of mine, with Docker 1.12.2. What am I missing?
The exception :
Exception in thread "main" SettingsException[Failed to open stream for url [/usr/share/elasticsearch/config/elasticsearch.yml]]; nested: AccessDeniedException[/usr/share/elasticsearch/config/elasticsearch.yml];
Likely root cause: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/config/elasticsearch.yml
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.Files.newByteChannel(Files.java:361)
at java.nio.file.Files.newByteChannel(Files.java:407)
at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
at java.nio.file.Files.newInputStream(Files.java:152)
at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1067)
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:88)
at org.elasticsearch.common.cli.CliTool.<init>(CliTool.java:107)
at org.elasticsearch.common.cli.CliTool.<init>(CliTool.java:100)
at org.elasticsearch.bootstrap.BootstrapCLIParser.<init>(BootstrapCLIParser.java:48)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:242)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
The system :
The Docker file :
FROM openjdk:8-jre
ENV VERSION 2.4.1
RUN groupadd -r elasticsearch && useradd -r -g elasticsearch elasticsearch
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 46095ACC8548582C1A2699A9D27D666CD88E42B4
RUN set -x \
&& apt-get update && apt-get install -y --no-install-recommends apt-transport-https && rm -rf /var/lib/apt/lists/* \
&& echo 'deb http://packages.elasticsearch.org/elasticsearch/2.x/debian stable main' > /etc/apt/sources.list.d/elasticsearch.list
RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends elasticsearch=$VERSION \
&& rm -rf /var/lib/apt/lists/*
ENV PATH /usr/share/elasticsearch/bin:$PATH
WORKDIR /usr/share/elasticsearch
RUN set -ex \
&& for path in \
./data \
./logs \
./config \
./config/scripts \
; do \
mkdir -p "$path"; \
chown -R elasticsearch:elasticsearch "$path"; \
done
COPY config ./config
VOLUME /usr/share/elasticsearch/data
VOLUME /usr/share/elasticsearch/logs
EXPOSE 9200 9300
USER elasticsearch
CMD elasticsearch
Aside the Dockerfile, lives the following file structure :
- config
- elasticsearch.yml
As the image works on another VM, I believe its configuration should be right. I do not think the problem comes from ElasticSearch either, as I seem to have another image having the same issue (H2). I'm beginner-level with both Docker and Linux.
Set the file permissions after you copy the config in:
COPY config ./config
RUN chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/config
You could also create and chown
the /usr/share/elasticsearch
directory as root then complete the rest of the steps dealing with the contents of /usr/share/elasticsearch
as USER elasticsearch
change your volume permissions to 777 example:- chmod 777 /path/to/volume
do not give recursive permissions
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.