running Neo4j graphgists locally with docker.io
Neo4j has a excellent tool for documenting graph models called graphgists. As the name suggests graphgists are typically stored as github gists in asciidoc format. Additionally to the regular asciidoc you can embed executable cypher and a Neo4j console in a graphgist. For most people it’s perfectly fine hosting their graphgists at github or dropbox. If you want to keep your graphgists private just use a secret gist.
One of my colleagues at Neo Technology recently pointed me to docker.io, a nice LXC based tool to create, maintain, run and share lightweight containers. To get familiar with docker I’ve decided to set up a small project to make graphgists and Neo4j console available in a docker container. This approach allows to handle with your graphgists 100% locally – nothing leaves the container.
How the docker container is built up
Docker containers are assembled by a cookbook called a dockerfile. It specifies the container you want to inherit from and then issue couple of commands to apply your customizations. In my case we need to install a servlet container (tomcat7 here). Neo4j console’s source repo is https://github.com/neo4j-contrib/rabbithole. Based on a recent change it now allows to build a war file ready for deployment into servlet containers. Of course we could have installed maven and clone the repo and exec
mvn war:war to build neo4j console. I’ve decided to provide and use a prebuilt war file located at bintray, this removes the need for downloaded a massive number of dependencies for the in-container maven installation. Neo4j console’s war file is deployed as
console.war and therefore available in the
console context of tomcat.
The graphgist repo is cloned into the location of tomcat’s root context and the location of CONSOLE_URL_BASE is adopted to the locally available neo4j console. Finally tomcat is started as a service. Here’s the full Dockerfile:
FROM quintenk/jdk7-oracle MAINTAINER Stefan Armbruster
# make sure the package repository is up to date RUN update-java-alternatives -s java-7-oracle RUN apt-get update && apt-get -y install tomcat7 git-core curl # set JAVA_HOME for tomcat to oracle jdk 7 RUN sed -i -e 's/#\(JAVA_HOME\)=\(.*\)\/.*$/\1=\2\/java-7-oracle/' /etc/default/tomcat7 # web rabbithole and place it under context /console RUN curl -L -o /var/lib/tomcat7/webapps/console.war "http://dl.bintray.com/sarmbruster/generic/rabbithole-2.0.0-RC1.war" # place graphgists in root context RUN rm -rf /var/lib/tomcat7/webapps/ROOT RUN git clone https://github.com/neo4j-contrib/graphgist.git /var/lib/tomcat7/webapps/ROOT # adopt CONSOLE_URL_BASE to point to locally installed rabbithole RUN sed -i -e "s/\(var CONSOLE_URL_BASE =\).*/\1 '\/console';/" /var/lib/tomcat7/webapps/ROOT/js/console.js; # fire tomcat up CMD service tomcat7 start && tail -f /var/log/tomcat7/catalina.out EXPOSE 8080
How to use the docker container
Of course you need to install docker locally. The procedure differs among operating system and is documented http://localhost:8080. To create a gist, open your favourite text editor and save a <myname>.adoc file in the local gist directory used above when starting docker. For some samples of graphgist files, see https://github.com/neo4j-contrib/graphgist/tree/master/gists.Pointing the browser to http://localhost:8080?myname (without .adoc) should render your graphgist.
Using docker ps and docker stop <containerId> can be used to stop the graphgist containter.
Since I’m absolutely new to docker there might be better and more elegant ways to achieve locally running graphgists. I’m looking forward to read your comments and feedback on this.