Docker + Elasticsearch + Kibana

# 目的
* DockerでElasticsearchとKibana

# 前提条件
* OS X 10.9.5
* DockerToolbox-1.9.1f 
 * docker-machine 0.5.4
 * docker 1.9.1

# Dockerが稼働する仮想マシンを作成
<pre>
$ docker-machine create --driver virtualbox dev
Creating CA: /Users/moriyasu/.docker/machine/certs/ca.pem
Creating client certificate: /Users/moriyasu/.docker/machine/certs/cert.pem
Running pre-create checks...
Creating machine...
(dev) Creating VirtualBox VM...
(dev) Creating SSH key...
(dev) Starting VM...
Waiting for machine to be running, this may take a few minutes...
Machine is running, waiting for SSH to be available...
Detecting operating system of created instance...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect Docker to this machine, run: docker-machine env dev
</pre>

# 仮想マシン確認
<pre>
$ docker-machine ls
NAME   ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER   ERRORS
dev    -        virtualbox   Running   tcp://192.168.99.100:2376           v1.9.1
</pre>

# docker-machine環境確認
<pre>
$ docker-machine env dev
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/moriyasu0410/.docker/machine/machines/dev"
export DOCKER_MACHINE_NAME="dev"
# Run this command to configure your shell:
# eval "$(docker-machine env dev)"
</pre>

# docker-machine環境設定
<pre>
$ export DOCKER_TLS_VERIFY="1"
$ export DOCKER_HOST="tcp://192.168.99.100:2376"
$ export DOCKER_CERT_PATH="/Users/moriyasu0410/.docker/machine/machines/dev"
$ export DOCKER_MACHINE_NAME="dev"
</pre>

# Elasticsearch Dockerfile作成
<pre>
$ cd
$ mkdir -p docker/es
$ cd docker/es
$ vim Dockerfile
</pre>

```sh:Dockerfile
FROM centos:6.6

RUN yum -y update

RUN yum install -y wget tar

RUN yum install -y java-1.8.0-openjdk
ENV JAVA_HOME /usr/lib/jvm/jre-1.8.0-openjdk.x86_64
ENV PATH $PATH:$JAVA_HOME/bin
ENV CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

ENV ES_PKG_NAME elasticsearch-1.7.4
RUN cd /
RUN wget https://download.elasticsearch.org/elasticsearch/elasticsearch/$ES_PKG_NAME.tar.gz
RUN tar xvzf $ES_PKG_NAME.tar.gz
RUN rm -f $ES_PKG_NAME.tar.gz
RUN mv /$ES_PKG_NAME /elasticsearch

CMD ["/elasticsearch/bin/elasticsearch"]

EXPOSE 9200 9300
```

# Dockerイメージ作成
<pre>
$ docker build --no-cache=true -t centos6/es .
</pre>

# Dockerコンテナ起動
<pre>
$ docker run --name es -t -i -d -p 9200:9200 -p 9300:9300 centos6/es
</pre>

# kibana Dockerfile
<pre>
$ cd
$ mkdir -p docker/kibana
$ cd docker/kibana
$ vim Dockerfile
$ vim kibana.yml
</pre>

```sh:Dockerfile
FROM centos:6.6

RUN yum -y update

RUN yum install -y wget tar

ENV KIBANA_PKG_NAME kibana-4.1.4-linux-x64
RUN cd /
RUN wget https://download.elastic.co/kibana/kibana/$KIBANA_PKG_NAME.tar.gz
RUN tar xvzf $KIBANA_PKG_NAME.tar.gz
RUN rm -f $KIBANA_PKG_NAME.tar.gz
RUN mv /$KIBANA_PKG_NAME /kibana
RUN cp /kibana/config/kibana.yml /kibana/config/kibana.yml.org
ADD kibana.yml /kibana/config/

CMD ["/kibana/bin/kibana"]

EXPOSE 5601
```

```kibana.yml
# Kibana is served by a back end server. This controls which port to use.
port: 5601

# The host to bind the server to.
host: "0.0.0.0"

# The Elasticsearch instance to use for all your queries.
elasticsearch_url: "http://es_alias:9200"

# preserve_elasticsearch_host true will send the hostname specified in `elasticsearch`. If you set it to false,
# then the host you use to connect to *this* Kibana instance will be sent.
elasticsearch_preserve_host: true

# Kibana uses an index in Elasticsearch to store saved searches, visualizations
# and dashboards. It will create a new index if it doesn't already exist.
kibana_index: ".kibana"

# If your Elasticsearch is protected with basic auth, this is the user credentials
# used by the Kibana server to perform maintence on the kibana_index at statup. Your Kibana
# users will still need to authenticate with Elasticsearch (which is proxied thorugh
# the Kibana server)
# kibana_elasticsearch_username: user
# kibana_elasticsearch_password: pass

# If your Elasticsearch requires client certificate and key
# kibana_elasticsearch_client_crt: /path/to/your/client.crt
# kibana_elasticsearch_client_key: /path/to/your/client.key

# If you need to provide a CA certificate for your Elasticsarech instance, put
# the path of the pem file here.
# ca: /path/to/your/CA.pem

# The default application to load.
default_app_id: "discover"

# Time in milliseconds to wait for elasticsearch to respond to pings, defaults to
# request_timeout setting
# ping_timeout: 1500

# Time in milliseconds to wait for responses from the back end or elasticsearch.
# This must be > 0
request_timeout: 300000

# Time in milliseconds for Elasticsearch to wait for responses from shards.
# Set to 0 to disable.
shard_timeout: 0

# Time in milliseconds to wait for Elasticsearch at Kibana startup before retrying
# startup_timeout: 5000

# Set to false to have a complete disregard for the validity of the SSL
# certificate.
verify_ssl: true

# SSL for outgoing requests from the Kibana Server (PEM formatted)
# ssl_key_file: /path/to/your/server.key
# ssl_cert_file: /path/to/your/server.crt

# Set the path to where you would like the process id file to be created.
# pid_file: /var/run/kibana.pid

# If you would like to send the log output to a file you can set the path below.
# This will also turn off the STDOUT log output.
# log_file: ./kibana.log

# A value to use as a XSRF token. This token is sent back to the server on each request
# and required if you want to execute requests from other clients (like curl).
# xsrf_token: ""

# Plugins that are included in the build, and no longer found in the plugins/ folder
bundled_plugin_ids:
 - plugins/dashboard/index
 - plugins/discover/index
 - plugins/doc/index
 - plugins/kibana/index
 - plugins/markdown_vis/index
 - plugins/metric_vis/index
 - plugins/settings/index
 - plugins/table_vis/index
 - plugins/vis_types/index
 - plugins/visualize/index
```

# Dockerイメージ作成
<pre>
$ docker build --no-cache=true -t centos6/kibana .
</pre>

# Dockerコンテナ起動
<pre>
$ docker run --name kibana --link es:es_alias -t -i -d  -p 5601:5601 centos6/kibana
</pre>

# Dockerコンテナ確認
<pre>
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                            NAMES
6a68ea6bccd6        centos6/kibana      "/kibana/bin/kibana"     5 seconds ago       Up 5 seconds        0.0.0.0:5601->5601/tcp                           kibana
1663201be1f3        centos6/es          "/elasticsearch/bin/e"   1 minutes ago       Up 1 minutes        0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   es
</pre>

# ブラウザで開く
http://192.168.99.100:5601