This is a minimal, generic Docker Compose configuration for running a single Neo4j instance. It can be customized for any database name and configuration.
-
Create data directories:
mkdir -p neo4j-data/{data,logs,import,plugins,conf} sudo chown -R 7474:7474 neo4j-data -
Create a
.envfile (optional, but recommended):cp .env.example .env # Edit .env with your settings ``` ```
-
Review the configuration options below and make any necessary changes to the
.envfile. -
Start Neo4j:
docker compose up -d
You can configure Neo4j in two ways:
Create a .env file in this directory with your settings:
# Container and database name
NEO4J_CONTAINER_NAME=my-neo4j
NEO4J_DATABASE=mydatabase
# Ports
NEO4J_HTTP_PORT=7474
NEO4J_BOLT_PORT=7687
# Data directory (absolute or relative path)
NEO4J_DATA_DIR=./neo4j-data
# Authentication
NEO4J_AUTH=neo4j/YourSecurePassword
# Memory settings (adjust based on your system)
NEO4J_HEAP_INITIAL=2G
NEO4J_HEAP_MAX=4G
NEO4J_OFF_HEAP_MAX=1G
NEO4J_TX_MAX=1G
NEO4J_TX_TOTAL_MAX=1GEdit the docker-compose.yml file and replace the environment variable references with your values.
Set NEO4J_DATA_DIR in your .env file or edit docker-compose.yml:
volumes:
- ${NEO4J_DATA_DIR:-./neo4j-data}/data:/data
- ${NEO4J_DATA_DIR:-./neo4j-data}/logs:/logs
- ${NEO4J_DATA_DIR:-./neo4j-data}/import:/import
- ${NEO4J_DATA_DIR:-./neo4j-data}/plugins:/plugins
- ${NEO4J_DATA_DIR:-./neo4j-data}/conf:/confImportant: Make sure these directories exist and have proper permissions:
sudo mkdir -p ${NEO4J_DATA_DIR:-./neo4j-data}/{data,logs,import,plugins,conf}
sudo chown -R 7474:7474 ${NEO4J_DATA_DIR:-./neo4j-data}If ports are already in use, change them in .env:
NEO4J_HTTP_PORT=8080
NEO4J_BOLT_PORT=8081Change the default password in .env:
NEO4J_AUTH=neo4j/YourSecurePasswordHereSet the database name in .env:
NEO4J_DATABASE=mydatabaseAdjust memory settings based on your system resources in .env:
NEO4J_HEAP_INITIAL=2G # Initial heap size
NEO4J_HEAP_MAX=4G # Maximum heap size
NEO4J_OFF_HEAP_MAX=1G # Off-heap memory-
Neo4j Browser (Web UI):
- URL:
http://localhost:${NEO4J_HTTP_PORT:-7474} - Default credentials:
neo4j/change-password(change this!)
- URL:
-
Bolt Connection (for applications):
- Connection string:
bolt://localhost:${NEO4J_BOLT_PORT:-7687} - Username:
neo4j - Password: (set in
NEO4J_AUTH)
- Connection string:
-
Data Storage:
- Database files:
${NEO4J_DATA_DIR:-./neo4j-data}/data(on your host machine) - Logs:
${NEO4J_DATA_DIR:-./neo4j-data}/logs - Import directory:
${NEO4J_DATA_DIR:-./neo4j-data}/import(place .dump files here) - Plugins:
${NEO4J_DATA_DIR:-./neo4j-data}/plugins - Configuration:
${NEO4J_DATA_DIR:-./neo4j-data}/conf
- Database files:
-
Start Neo4j:
docker compose up -d
-
Stop Neo4j:
docker compose stop
-
View Logs:
docker compose logs -f
-
Remove Container (keeps data):
docker compose down
-
Remove Container and Volumes (deletes data):
docker compose down -v
The container name is set by NEO4J_CONTAINER_NAME (default: neo4j). You can also manage it directly:
docker start ${NEO4J_CONTAINER_NAME:-neo4j}
docker stop ${NEO4J_CONTAINER_NAME:-neo4j}
docker logs ${NEO4J_CONTAINER_NAME:-neo4j}Use the provided graph-data.sh script to create and restore database dumps:
# Create a dump
./graph-data.sh dump mydatabase my-neo4j ./neo4j-data
# Load a dump
./graph-data.sh load mydatabase my-neo4j ./neo4j-dataRequired arguments:
DATABASE_NAME: Name of the Neo4j databaseCONTAINER_NAME: Name of the Neo4j containerDATA_DIR: Path to the data directory (absolute or relative)
Important for loading dumps:
Before loading a dump, make sure the dump file is placed in the import/ folder within your data directory. The script expects the dump file at ${DATA_DIR}/import/${DATABASE_NAME}.dump or in a directory structure at ${DATA_DIR}/import/${DATABASE_NAME}/.
See the script for more details.