Elasticsearch-7.15.1 Dockerfile

Elasticsearch-7.15.1 Dockerfile

Elasticsearch-7.15.1 Dockerfile

--------------------------------------------------------------------------------------------------

touch Dockerfile 

--------------------------------------------------------------------------------------------------
# Pull base image  
FROM docker.io/centos:latest
  
MAINTAINER crabdave "[email protected]"  

# Usage: USER [UID]
USER root

# Add usergroup
RUN groupadd es
# Add user and set group
RUN useradd -g es  es

# Install gosu for sudo function support
ADD gosu-amd64 /home/es/
RUN mv /home/es/gosu-amd64 /usr/local/bin/gosu \
  && chmod +x /usr/local/bin/gosu \
  && gosu nobody true


# Config java environment
ADD jre-8u311-linux-x64.rpm /root/
RUN cd /root/ \
   &&rpm -ivh jre-8u311-linux-x64.rpm

# Setting java config
RUN echo "export JAVA_HOME=/usr/java/jre1.8.0_311-amd64" >>  /etc/profile
RUN echo "export PATH=\$PATH:\$JAVA_HOME/bin" >>  /etc/profile

# Config elasticsearch
ADD elasticsearch-7.15.1-linux-x86_64.tar.gz /home/es/
RUN cd  /home/es/ \
   && chown -R es:es * \
   && cd elasticsearch-7.15.1/config/ \
   && echo "http.cors.enabled: true" >> elasticsearch.yml \
   && echo "http.cors.allow-origin: \"*\" " >> elasticsearch.yml \
   && sed -i 's/#network.host: 192.168.0.1/network.host: 0.0.0.0/' elasticsearch.yml \
   && sed -i 's/#cluster.initial_master_nodes: \[\"node-1\", \"node-2\"\]/cluster.initial_master_nodes: \[\"node-1\"\]/' elasticsearch.yml 

# Expose ports.  
EXPOSE 9200
EXPOSE 9300

# Configuration effective
RUN source  /etc/profile \
   && echo $JAVA_HOME \
   && java -version

# Setting vm.max_map_count
RUN cp  /etc/sysctl.conf /home/es/ \
   && echo "vm.max_map_count=262144" >> /home/es/sysctl.conf
# With "--privileged=true" when running container
# sudu es user to start elasticsearch server
CMD mv /home/es/sysctl.conf /etc/sysctl.conf\
   && /sbin/sysctl -p \
   && cat /etc/sysctl.conf \
   && gosu es ./home/es/elasticsearch-7.15.1/bin/elasticsearch



--------------------------------------------------------------------------------------------------

docker build -t elasticsearch .

--------------------------------------------------------------------------------------------------

docker run -d --restart=always --privileged=true -p9200:9200 -p9300:9300 elasticsearch:latest 

docker ps

docker logs -f 64d5d132f3e1

--------------------------------------------------------------------------------------------------

curl http://localhost:9200

--------------------------------------------------------------------------------------------------





你可能感兴趣的:(docker,dockerfile,shell,centos,elasticsearch)