Running Neo4j in a Docker container
October 18, 2016
neo4j
docker
Running Neo4j inside a Docker container is super-simple. In this short tutorial we will create a Docker configuration for Neo4j and create a default Neo4j configuration template for later tweaking.
Configuring Docker
First, we need a docker-compose.yml
file. Create the file in your project root.
version: "2"
services:
neo:
image: neo4j:3.0
mem_limit: 4096m
restart: on_failure
ports:
- "7474"
- "7687"
volumes:
- ./data:/data
- ./conf:/conf
This will create a Docker image with 4Gb
of memory, that auto-restarts after a crash. Because we want
to access Neo4j services, we have to expose ports 7474
(Rest API) and 7687
(Bolt protocol).
volumes
gives us persistent storage of Neo4j database (/data
) and configuration (/conf
).
Both directories are currently empty, but we will fix that shortly.
Building the image
With the docker-compose.yml
file all ready, we just execute the following docker-compose
command.
docker-compose build
That’s it. Our custom Docker container image is ready to be launched.
Dumping the default configuration
docker-compose run --rm neo dump-config
This command will spawn a container instance of neo
image, defined in our docker-compose.yml
file and run dump-config
command inside that instance.
This is a special command, given to us by the folks from Neo4j that copies its configuration files
to the /conf
directory. After running this command you should see new files in your conf
directory inside your project root on the host.
Configuring Neo4j
In the previous step, dump-config
gave us a default template on which we will build upon. Files
neo4j.conf
and neo4j-wrapper.conf
contain settings for the Neo4j server and
the Java Virtual Machine (JVM)
.
For now, these default settings will be enough, as the details on this subject are beyond the scope of the tutorial.
You can look up futher information at neo4j.com/docs.
Launching Neo4j
We are now ready to launch an instance of Neo4j server.
docker-compose up
Give Neo4j a few seconds to load up then head to http://localhost:7474
.