Portrait of Martijn

Solr on Docker

14 Aug 2013

/Looking for an up-to-date solr docker image? See/ makuk66/docker-solr

When I last experimented with LXC by hand a couple of years ago, it was a bit of a hassle. Now docker opens up some new possibilties, and I finally spent some time trying that out.

I followed the getting started guide guide, with the Ubuntu installation instructions, on Ubuntu Raring 13.04.

I ran into one minor issue: docker failed with a "/var/run/docker.sock: permission denied" error due to a bug which has a workaround of:

sudo chmod 777 /var/run/docker.sock

Next we'll prepare an image to run Solr, similar to the solr tutorial.

First, download Solr, to the docker host:

wget http://www.mirrorservice.org/sites/ftp.apache.org/lucene/solr/4.4.0/solr-4.4.0.tgz

then create a trivial Dockerfile (see Dockerfile Builder docs):

cat > Dockerfile <<EOM
#
# VERSION 0.1

FROM    ubuntu
MAINTAINER  Martijn Koster "mak-docker@greenhills.co.uk"

RUN mkdir -p /opt
ADD solr-4.4.0.tgz /opt/solr-4.4.0.tgz
RUN tar -C /opt --extract --file /opt/solr-4.4.0.tgz
RUN apt-get update
RUN apt-get --yes install openjdk-6-jdk
EXPOSE 8983
CMD ["/bin/bash", "-c", "cd /opt/solr-4.4.0/example; java -jar start.jar"]
EOM

Then create the template:

docker build -t makuk66/solr4 .

And run it:

docker run makuk66/solr4

which starts executing Solr in about a second. You can see what port was used for the port forwarding with:

mak@macro:~$ docker ps
ID                  IMAGE                  COMMAND                CREATED             STATUS              PORTS
7e7806800146        makuk66/solr4:latest   /bin/bash -c cd /opt   3 hours ago         Up 3 hours          49153->8983         

so I could connect to http://macro.lan:49153/solr and found Solr running. I can see changes made in the container with docker diff 7e7806800146, and export files from the container with e.g. docker export 7e7806800146 | tar xvf - ./opt/solr-4.4.0/example/logs/solr.log.

I also tried the Virtualbox/Vagrant method on my MacBook Pro but ran into some issues:

  • after the git clone I needed to modify the Vagrantfile because of a VirtualBox conflict:

    config.vm.forward_port 4243, 1234

  • Because of the VirtualBox setup, to get access from my Mac (and other hosts on the LAN), I needed to add a NAT port mapping in VirtualBox (Settings -> Network -> Port Forwarding, I added a mapping from 49153 -> 49153). With that in place, I can get to Solr on http://localhost:49153/solr/#/

  • I get to Solr, but the UI is broken; it looks like the require.js Javascript file gets truncated. Perhaps a problem with the VirtualBox NAT, they had similar problems in the past? I've not looked into that.

I gave up on that for now and switched back to my Linux server.

I can imagine this setup might be useful in clean-slate component testing. Most of my integration test deployments are specifically for clusters on multi-VM configurations, which this seems less suited for. There is obviously a good use-case for this in isolating web serving, though I'll hold off on that until the release a production-ready version. It will be interesting keeping an eye on the docker blog to see what other applications turn up.

Update: See a follow-up post on Search Hub: SolrCloud on Docker