Docker 101 : Creating an Elasticsearch image

Creating an image in Docker is rather easy and well documented.

You start by editing a file which describes the image, then run a few commands, and voilĂ .

In this post we’ll cover how to create a very basic Docker image which will let us spawn elasticsearch instances very easily.

Create the Docker image

The following Dockerfile describes the image we are building :

It basically says that :

  • We base our image off a current debian
  • We extract the Java and Elasticsearch archives into /opt
  • We set a couple of environment variables which will make things run smoothly
  • We expose the two ports Elasticsearch relies on for communicating with the outside world
  • And finally we state that a container based on this image will automaticall fire up Elasticsearch

Build the image

Once the file is edited to our tastes, it’s merely a question of running the following command to build the image :

[root@linuxdev elastic]# pwd
[root@linuxdev elastic]# ls -l
total 88568
-rw-r--r--. 1 root root      234 Feb 24 21:23 Dockerfile
drwxr-xr-x. 3 root root     4096 Mar  3 21:20 elasticsearch-1.4.4
-rw-r--r--. 1 root root 27900004 Feb 24 20:55 elasticsearch-1.4.4.tar.gz
-rw-r--r--. 1 root root 62779561 Feb 24 20:30 jre-8u31-linux-x64.tar.gz
[root@linuxdev elastic]# docker build --tag="killermouse0/elastic" .
Step 1 : ADD jre-8u31-linux-x64.tar.gz /opt
 ---> Using cache
 ---> 8b0c76b3b5b2
Step 7 : ENTRYPOINT /opt/elasticsearch-1.4.4/bin/elasticsearch
 ---> Using cache
 ---> 8f64901f4408
Successfully built 8f64901f4408

Starting a container with that image

Now that the image is ready, we can start a container based on this image as shown below :

docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch killermouse0/elasticsearch

The -p option will bind the ports of the container to the host, which will let us connect to the Elasticsesarch instance. Let’s check that the instance is up and running :

[root@linuxdev ~]# curl -XGET http://localhost:9200/
  "status" : 200,
  "name" : "Skywalker",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "1.4.4",
    "build_hash" : "c88f77ffc81301dfa9dfd81ca2232f09588bd512",
    "build_timestamp" : "2015-02-19T13:05:36Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.3"
  "tagline" : "You Know, for Search"

It’s all good.