Building Docker image with Solr

There are two ways to build docker image:

  • Running an image, modifying and committing it. This requires to access live container.
  • Using Dockerfile and build it.

Let’s take an example of creating a docker image with Solr from scratch:

Step1: Pull centos image which will act as base image.

docker pull centos:latest

Step2: Run container, map ports and mount base machine directory to container

docker run -d --name solr1 -v /home/omit/project/:/home/omit/project/ -p -p centos:latest

omi1 -d flag will run container in detach mode (as daemon thread).

-v flag mounts the volume.

-p flag is used to expose ports

Step3: Access docker container with exec command

docker exec -it solr1 bash


Above command will open bash session for the solr1 container. Now we can change directory inside container to /home/project and install solr.

So, for inside container we need to install following things for solr:

  • -wget for downloading
  • -install unzip utility
  • -jre required by solr

Step3.1: Install wget

Yum install –y wget

Step3.2 Download and install unzip utility

wget rpm –ivh $downloaded_file


Step3.3: Download jre

wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" "" -P /home/omit/project


Step3.4: Give execute permission to downloaded file & install jre

rpm –ivh $jre_downloaded


Step3.5: Download and unzip solr



Step3.6: Give execute permission to solr installation directory and change you directory to bin inside solr installation directory and run:

./solr start -p 8983


Step3.7: Test if the Solr is running locally,


Step4: Exit container and commit the changes

docker commit -m "solr installed" -a "Omi Tewary" $container_ID solr/digital:1.0


Step5: Test your image by doing docker images


Now you can save this image as a tar file. For that you will have to save this image as a tar file.

docker save –o <image name>


To load image,

docker load -i <path to image tar file>


Building image with Dockerfile

Dockerfile is also referred to as docker build file. In Dockerfile we specify docker set of instructions. The instructions we give in Dockerfile are set of commands. An equivalent Dockerfile for building above image would be as,


  • The FROM instruction set the base image for subsequent instruction.
  • The MAINTAINER instruction allows you to set the author.
  • RUN command will execute the command on the bash of container.
  • WORKDIR specify the working directory of container.
  • VOLUME is used for mounting base machine directory to the container.
  • EXPOSE is used for exposing container ports.

Apart from this, there are other instructions also available. Refer docker documentation for that. After writing your docker file, execute the following command from the same directory where you have to save your Dockerfile.

Write a comment
Cancel Reply
  • ken May 17, 2018, 8:55 am
    awesome post. but why would you include images with such poor resolution? Is the related code available anywhere?