...

/

Docker Setup

Docker Setup

Learn how to set up Elasticsearch and Kibana on the Educative platform.

Dockerfile

First, let’s have a look at the Dockerfile used to set up Elasticsearch and Kibana.

Press + to interact
FROM ubuntu:20.04
# Installing helper packages
RUN apt-get update &&\
apt-get install -y gnupg2 &&\
apt-get install -y curl
# Installing Elasticsearch
RUN curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - &&\
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-7.x.list &&\
apt-get update &&\
apt-get install elasticsearch
# Installing Kibana
RUN apt-get update &&\
apt-get install kibana

The Dockerfile starts with specifying the base image in line 1, ubuntu:20.04 in our case. Please avoid using the latest tag for the base image. Instead, specify the exact version, as we’ve specified 20.04. After that, we just installed some helper packages in lines 4-7.

Let’s briefly talk about the installation of Elasticsearch and Kibana.

Installing Elasticsearch

  • In line 9, we used cURL to import the Elasticsearch public GPG key into APT. Note that we are using the arguments -fsSL to silence all progress and possible errors (except for a server failure) and to allow cURL to make a request on a new location if redirected. Pipe the output of the cURL command into the apt-key program, which adds the public GPG key to APT.
  • Next, in line 10, we added the Elastic source list to the sources.list.d directory, where APT will look for new sources.
  • In line 11, we updated the package lists so APT will read the new Elastic source.
  • Finally, we installed Elasticsearch in line 12.

Installing Kibana

The Kibana is installed in lines 15–16.

Tarball

The Dockerfile and all other necessary files are uploaded to the Educative platform in the form of a tarball. The tarball can be generated using the following command:

tar -zcvf Elasticsearch.tar.gz Dockerfile

The tarball for setting up Elasticsearch and Kibana on the Educative platform can be downloaded from the link below:

Download Tarball for Elasticsearch

Docker job

The following docker job can be used to run Elasticsearch and Kibana:

We’ve put 5601 in the “Application Port” because Kibana runs on this port by default. Apart from that, the “Force Relaunch On Run” option has been set to true which means that the server will launch from scratch every time the “Run” button is pressed. In that case, we don’t need the “Run Script” too, that’s why we’ve used the : command which apparently does nothing.

Start script

cp usercode/kibana.yml /etc/kibana && nohup service elasticsearch start && service kibana start

The “Start Script” mainly performs the following three steps:

  1. Copies the updated kibana.yml from the usercode directory to the /etc/kibana directory. We’ll talk about this approach in detail in the next lesson.
  2. Starts the Elasticseach service using nohup. We use nohup (“no hang up”) so that the output that would normally go to the terminal goes to a file called nohup. In this way, the terminal gets free and we can execute the next commands.
  3. Starts the Kibana service.

Access this course and 1200+ top-rated courses and projects.