I am trying to build a docker image that has elastic search running and creating a container from that image.
Below is the content of my Dockerfile:
FROM adoptopenjdk/openjdk8:alpine
MAINTAINER rando
COPY elasticsearch-2.1.1.tar.gz /tmp
RUN cd /tmp \
&& tar -xzf elasticsearch-2.1.1.tar.gz \
&& ls \
&& mv elasticsearch-2.1.1 /usr/share/elasticsearch \
&& ls /usr/share \
&& adduser -DH -s /sbin/nologin elasticsearch \
&& chown -R elasticsearch:elasticsearch /usr/share/elasticsearch \
&& echo "Creating Elasticsearch Paths..." \
&& for path in /usr/share/elasticsearch/data /usr/share/elasticsearch/logs /usr/share/elasticsearch/config /usr/share/elasticsearch/config/scripts /usr/share/elasticsearch/plugins ; do mkdir -p "$path"; done \
&& chown -R elasticsearch:elasticsearch /usr/share/elasticsearch \
&& ls /usr/share/elasticsearch
COPY elasticsearch.yml /usr/share/elasticsearch/config
COPY elastic-entrypoint.sh /
RUN chmod +x /elastic-entrypoint.sh
ENV ES_HOME=/usr/share/elasticsearch
ENV PATH=${ES_HOME}/bin:${PATH}
RUN echo "$PATH"
VOLUME ["/usr/share/elasticsearch/data"]
EXPOSE 9200 9300
ENTRYPOINT ["/elastic-entrypoint.sh"]
CMD ["elasticsearch"]
I am to build successfully the image from the docker file when running the command below:
docker build -t elasticsearch .
When I try to create the container with the command below, I am facing some issues:
docker run -d --network host elasticsearch
The container is created but is terminates directly.
Below is the content when running the docker logs for the container:
/elastic-entrypoint.sh: exec: line 20: su-exec: not found
Below is the content of elastic-entrypoint.sh file:
#!/bin/sh
set -e
# Add elasticsearch as command if needed
if [ "${1:0:1}" = '-' ]; then
set -- elasticsearch "$@"
fi
# Drop root privileges if we are running elasticsearch
# allow the container to be started with `--user`
if [ "$1" = 'elasticsearch' -a "$(id -u)" = '0' ]; then
# Change the ownership of /usr/share/elasticsearch/data to elasticsearch
chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data
set -- su-exec elasticsearch tini -- "$@"
fi
exec "$@"
It seems that set -- su-exec elasticsearch tini -- "$@"
is not working.
I will appreciate any help or guidance to fix this issue.
Regards, Rando.
Update............................................................
I modified the file as below:
#set -- su-exec elasticsearch tini -- "$@"
set -- su -c elasticsearch tini -- "$@"
It showed the error:
su: unknown user tini
It is not recognizing the user.
Update 2...............................................................
I modified the dockerfile by adding the command for installation of su-exe
like below:
# Install required packages
RUN apk add --no-cache bash su-exec
The container exited with the error below:
su-exec: tini: No such file or directory
Try to use set -- su -c elasticsearch tini -- "$@"
Also you do not need to define CMD ["elasticsearch"]
inside Dockerfile. Just put inside elastic-entrypoint.sh file.
The cause of the error was that adoptopenjdk/openjdk8:alpine
does not include the su-exec package. I modified the dockerfile as below:
FROM adoptopenjdk/openjdk8:alpine
MAINTAINER rando
# Install required packages
RUN apk add --no-cache bash su-exec
RUN apk add --update tini
COPY elasticsearch-2.1.1.tar.gz /tmp
...
And adding su-exec
package fixed the issue in my case.
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.