Deployment of Neo4j Docker container with APOC and Graph Algorithms plugins

Mai Ngoc Kien
The Startup
Published in
3 min readMay 11, 2020

--

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.

I do not know the name of the flower T.T, and my favorite super market is over there.

Neo4j 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 plugins directory.

Graph Algorithm: https://github.com/neo4j-contrib/neo4j-graph-algorithms/releases

APOC: https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases

Edit the configuration file

Modify neo4j.conf by adding these line:

dbms.security.procedures.whitelist=algo.*,apoc.*
dbms.security.procedures.unrestricted=algo.*,apoc.*

Deploy the Neo4j container

Run the container, now using folder under working directory.

docker run -d \
--publish=7474:7474 \
--publish=7687:7687 \
--volume=$(pwd)/data:/data \
--volume=$(pwd)/logs:/logs \
--volume=$(pwd)/conf:/conf \
--volume=$(pwd)/plugins:/plugins \
--env=NEO4J_AUTH=none \
--name my_neo4j neo4j:3.2.3

The container:

  • Run as daemon
  • Publish 2 ports: 7474, 7687
  • Data is stored in data directory
  • Log is written to logs directory
  • Config is used from conf directory
  • Plugins are used in plugins directory
  • No authentication is required (we could set/require it by using --env NEO4J_AUTH=neo4j/<password> instead)

Confirm deployment

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:

CALL algo.list();
CALL apoc.index.list();

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"))

References

https://janikarhunen.fi/setting-up-dockerized-neo-4-j-for-data-analysis

--

--