From 8ae15896110f01bcabfd4a3c001bbfb7ba1f235a Mon Sep 17 00:00:00 2001 From: Christophe Labouisse Date: Sat, 24 Jan 2015 17:13:03 +0100 Subject: [PATCH] Java upgrade (Fix #21) and entry point wrapper. The current dockerfile elastic search uses Java 1.7 and runs elasticsearch as root while Docker best practices recommends to run the service as a normal user. - Use a lightweight Java 8 container based on OpenJDK - Use ENTRYPOINT rather than CMD - Add a wrapper script to drop privilege and ease running the container with parameters. --- Dockerfile | 11 ++++++----- README.md | 4 ++-- docker-entry-point.sh | 11 +++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100755 docker-entry-point.sh diff --git a/Dockerfile b/Dockerfile index 1478203c228..b89385e3c53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,16 +5,15 @@ # # Pull base image. -FROM dockerfile/java:oracle-java8 +FROM ggtools/java8 ENV ES_PKG_NAME elasticsearch-1.4.2 # Install Elasticsearch. RUN \ cd / && \ - wget https://download.elasticsearch.org/elasticsearch/elasticsearch/$ES_PKG_NAME.tar.gz && \ - tar xvzf $ES_PKG_NAME.tar.gz && \ - rm -f $ES_PKG_NAME.tar.gz && \ + curl -k https://download.elasticsearch.org/elasticsearch/elasticsearch/$ES_PKG_NAME.tar.gz | \ + tar -xvzf - && \ mv /$ES_PKG_NAME /elasticsearch # Define mountable directories. @@ -22,12 +21,14 @@ VOLUME ["/data"] # Mount elasticsearch.yml config ADD config/elasticsearch.yml /elasticsearch/config/elasticsearch.yml +ADD docker-entry-point.sh /elasticsearch/bin/docker-entry-point.sh # Define working directory. WORKDIR /data # Define default command. -CMD ["/elasticsearch/bin/elasticsearch"] +ENTRYPOINT [ "/elasticsearch/bin/docker-entry-point.sh" ] +CMD [""] # Expose ports. # - 9200: HTTP diff --git a/README.md b/README.md index 12a14b006da..639c1bd3df4 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This repository contains **Dockerfile** of [Elasticsearch](http://www.elasticsea ### Base Docker Image -* [dockerfile/java:oracle-java8](http://dockerfile.github.io/#/java) +* [ggtools/java8](https://registry.hub.docker.com/u/ggtools/java8) ### Installation @@ -37,7 +37,7 @@ This repository contains **Dockerfile** of [Elasticsearch](http://www.elasticsea 3. Start a container by mounting data directory and specifying the custom configuration file: ```sh - docker run -d -p 9200:9200 -p 9300:9300 -v :/data dockerfile/elasticsearch /elasticsearch/bin/elasticsearch -Des.config=/data/elasticsearch.yml + docker run -d -p 9200:9200 -p 9300:9300 -v :/data dockerfile/elasticsearch -Des.config=/data/elasticsearch.yml ``` After few seconds, open `http://:9200` to see the result. diff --git a/docker-entry-point.sh b/docker-entry-point.sh new file mode 100755 index 00000000000..5816d70737e --- /dev/null +++ b/docker-entry-point.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +if [ -z "$1" -o "${1:0:1}" = '-' ]; then + chown -R default /data + + exec gosu default /elasticsearch/bin/elasticsearch "$@" +fi + +exec "$@"