Neo4j is the world’s leading graph database. Fortunately, Neo Technology publishes official Neo4j Docker images which makes it very easy to get started. Once you have Docker running, simply use the the following command to start running Neo4j in a new container (adjust Neo4j version as necessary):

docker run \
    -p=7474:7474 \
    -p=7687:7687 \
    -v=$HOME/neo4j/data:/data \
    -v=$HOME/neo4j/logs:/logs \
    neo4j:3.1

The -p (or --publish) options above binds the exposed ports 7474 and 7687 in the Docker container to the same ports on the local machine. The -v (or --volume) options mount the local $HOME/neo4j/data directory as the /data directory in the Docker container, as well as mounts the local $HOME/neo4j/logs directory as the /logs directory in the Docker container. The actual Neo4j databases and logs are stored in these directories.

The directories mounted with the -v option will remain on the local filesystem even after the container is stopped or deleted. This means that future containers can use this same data/database. This also means that if you want to create a new container with a new database, you must change the locations of these local directories in the run command.

It is also common to load data from files into your Neo4j database. For this to work these files must be available in your Docker container. Your Docker container will by default try to load (when using the LOAD CSV command) data from within the container at /var/lib/neo4j/import. Mounting a local directory as /var/lib/neo4j/import can make importing data much convenient. For example:

docker run \
    -p=7474:7474 \
    -p=7687:7687 \
    -v=$HOME/neo4j/data:/data \
    -v=$HOME/neo4j/logs:/logs \
    -v=$HOME/local_import_dir:/var/lib/neo4j/import \
    neo4j:3.1

Once your container has started you should be able to interact with Neo4j through the web based UI in a browser at http://localhost:7474.

Leave a Reply

Running Neo4j 3.x on Docker