title: Dockerfile with entrypoint for executing bash script
body: <p>I downloaded docker files from official repository (version 2.3), and now I want to build the image and upload some local data (<code>test.json</code>) into the container. It is not enough just to run <code>COPY test.json /usr/share/elasticsearch/data/</code>, because in this case the indexing of data is not done.</p>
  
  <p>What I want to achieve is to be able to run <code>sudo docker run -d -p 9200:9200 -p 9300:9300 -v /home/gosper/tests/tempESData/:/usr/share/elasticsearch/data test/elasticsearch</code>, and after its execution I want to be able to see the mapped data on <code>http://localhost:9200/tests/test/999</code>.</p>
  
  <p>If I use the below-given Dockerfile and *sh script, then I get the following error: <code>Failed to connect to localhost port 9200: Connection refused</code></p>
  
  <p>This is the Dockerfile from which I build the image:</p>
  
  <pre><code>FROM java:8-jre
  
  # grab gosu for easy step-down from root
  ENV GOSU_VERSION 1.7
  RUN set -x \
      &amp;&amp; wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
      &amp;&amp; wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
      &amp;&amp; export GNUPGHOME="$(mktemp -d)" \
      &amp;&amp; gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
      &amp;&amp; gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
      &amp;&amp; rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
      &amp;&amp; chmod +x /usr/local/bin/gosu \
      &amp;&amp; gosu nobody true
  
  # https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html
  # https://packages.elasticsearch.org/GPG-KEY-elasticsearch
  RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 46095ACC8548582C1A2699A9D27D666CD88E42B4
  
  ENV ELASTICSEARCH_VERSION 2.3.4
  ENV ELASTICSEARCH_REPO_BASE http://packages.elasticsearch.org/elasticsearch/2.x/debian
  
  RUN echo "deb $ELASTICSEARCH_REPO_BASE stable main" &gt; /etc/apt/sources.list.d/elasticsearch.list
  
  RUN set -x \
      &amp;&amp; apt-get update \
      &amp;&amp; apt-get install -y --no-install-recommends elasticsearch=$ELASTICSEARCH_VERSION \
      &amp;&amp; rm -rf /var/lib/apt/lists/*
  
  ENV PATH /usr/share/elasticsearch/bin:$PATH
  
  WORKDIR /usr/share/elasticsearch
  
  RUN set -ex \
      &amp;&amp; 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
  
  COPY docker-entrypoint.sh /
  
  EXPOSE 9200 9300
  
  RUN chmod +x /docker-entrypoint.sh
  
  ENTRYPOINT ["/docker-entrypoint.sh"]
  CMD ["elasticsearch"]
  
  COPY template.json /usr/share/elasticsearch/data/
  
  RUN /bin/bash -c "source /docker-entrypoint.sh"
  </code></pre>
  
  <p>This is the <code>docker-entrypoint.sh</code> in which I added the line <code>curl -XPOST http://localhost:9200/uniko-documents/document/978-1-60741-503-9 -d "/usr/share/elasticsearch/data/template.json"</code>:</p>
  
  <pre><code>#!/bin/bash
  
  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 -- gosu elasticsearch "$@"
      #exec gosu elasticsearch "$BASH_SOURCE" "$@"
  fi
  
  curl -XPOST http://localhost:9200/tests/test/999 -d "/usr/share/elasticsearch/data/test.json"
  
  # As argument is not related to elasticsearch,
  # then assume that user wants to run his own process,
  # for example a `bash` shell to explore this image
  exec "$@"
  </code></pre>