Saturday, February 27, 2021

Using Docker Playground to Run Solr

Recently, I wanted to run through some Solr documentation, and I wanted a clean Solr instance with demo contents. I was able to do this pretty cleanly on the Play with Docker site (requires a free Docker account).  

Here are the steps:

Go to Play with Docker: https://labs.play-with-docker.com/

Click Add New Instance.



On the command line, run:

>docker run  -dp 8983:8983 --name my-solr solr solr-demo

What this means:

  • -d run detached (rather than sending output to the command line)
  • -p 8983:8983 set host port 8983 to container port 8983
  • --name allows running commands without using the container generated ID "e3..." below
  • The first "solr", the name of the image to pull from Dockerhub.  Defaults to latest, but I could have put solr:8.4 if I wanted to be more specfic.
  • "solr-demo" is a script written by the docker image maintainers to get this running. 

This runs pretty fast on this environment:


You'll see an 8983 button which will allow you to access Solr.


Click on the 8983 button, switch the Core dropdown to "demo", click Query, then "Execute Query" to see demo contents:



You can now run through a tutorial like "Solr in 5 Minutes": http://www.solrtutorial.com/solr-in-5-minutes.html

If you want to access the command line of the instance, run this:

>docker exec -it my_solr /bin/bash

exec is for running commands on containers that are up.  This opens a command line inside the container. 

Type >bin/solr --help to see Solr commands:



Or >bin/solr status



Since Play with Docker is web based, this is a good way of getting a first taste for Docker even if you don't have it installed. 

This environment goes away in a 4 hours, but you can stop the instance with >docker rm -f my_solr should you want to start fresh.  (-f means "force", so you can remove a running container)

Note: I tried to do this locally, and was running into an issue with docker exiting after setting up the instance.  Docker Playground stepped around this.  When I figure out what I'm doing wrong locally, I'll update this post.

No comments:

Post a Comment