Deployment of Neo4j Docker container with APOC and Graph Algorithms plugins
Recently, I have learnt to use a graph database called Neo4j. And I do not want to install a lot of software on the computer. Hence, Docker image is a good option.
Neo4j docker image provides an awesome graph database with convenient web UI. However, it does not include plugins which support additional library (such as APOC, Graph Algorithms). I need to do some manual set up before being able to deploy the container with plugins.
APOC stands for Awesome Procedures on Cypher, a standard utility library for common procedures and functions. This allowed developers across platforms and industries to use a standard library for common procedures and only write their own functionality for business logic and use-case-specific needs.
Graph algorithms provide one of the most potent approaches to analyzing connected data because their mathematical calculations are specifically built to operate on relationships. They describe steps to be taken to process a graph to discover its general qualities or specific quantities.
Note: The Graph Algorithms Library has been deprecated by the Graph Data Science Library (GDS).
Set up directories for volumes
I need to create some directories under the work directory for Docker volumes. Volumes are the preferred mechanism for persisting data generated by and used by Docker containers.
$ mkdir data
$ mkdir logs
$ mkdir conf
$ mkdir plugins
Next, I need to generate the initial config file, I can dump it from the container
$ docker run --rm --volume=$(pwd)/conf:/conf neo4j:3.5.3 dump-config
which will download the configuration file to conf directory under the current host directory.
Download the plugin
In order to use plugins, find and download jar file of the plugins released on their websites, and store it in the
Graph Algorithm: https://github.com/neo4j-contrib/neo4j-graph-algorithms/releases
Edit the configuration file
neo4j.conf by adding these line:
Deploy the Neo4j container
Run the container, now using folder under working directory.
docker run -d \
--name my_neo4j neo4j:3.2.3
- Run as daemon
- Publish 2 ports: 7474, 7687
- Data is stored in
- Log is written to
- Config is used from
- Plugins are used in
- No authentication is required (we could set/require it by using
Check the status of the container by command:
$ docker ps
If the container is running, we can access to the Neo4j Browser UI at the address
http://localhost:7474 and check the installation of the plugins by the Cypher command:
If you prefer Python,
py2neo module provides a way to connect to the database via this code:
from py2neo import Graph
graph = Graph("bolt://localhost:7474", auth=("neo4j_username", "password"))