top of page
  • Writer's pictureRevanth Reddy Tondapu

Running Neo4j with Docker Compose: A Step-by-Step Guide


Running Neo4j with Docker Compose
Running Neo4j with Docker Compose

Introduction

Neo4j is a highly popular graph database management system, known for its efficiency in handling complex relational data. Utilizing Docker Compose to run Neo4j simplifies the setup process, making it easy to manage and scale your Neo4j instances. In this blog post, we'll walk through how to set up and run Neo4j using Docker Compose.


Why Use Docker Compose?

Docker Compose is a tool for defining and running multi-container Docker applications. Using Compose, you can define a multi-container environment in a single YAML file and spin up the entire setup with a single command. This is particularly useful for applications like Neo4j, which might require multiple configurations and dependencies.


Prerequisites

Before we start, ensure you have Docker and Docker Compose installed on your system. You can download them from the Docker official website.


Step-by-Step Setup


Step 1: Create a Docker Compose File

Start by creating a docker-compose.yml file in your project directory. This file will define the services, networks, and volumes required for running Neo4j.

version: '3.8'

services:
  neo4j:
    image: neo4j:latest
    container_name: neo4j
    ports:
      - "7474:7474"   # HTTP port for Neo4j Browser and API
      - "7687:7687"   # Bolt port for database connections
    environment:
      - NEO4J_AUTH=neo4j/securepassword   # Custom username and password
      - NEO4J_dbms_memory_pagecache_size=4G
      - NEO4J_dbms_memory_heap_initial__size=2G
      - NEO4J_dbms_memory_heap_max__size=4G
    volumes:
      - neo4j_data:/data
      - neo4j_logs:/logs
      - neo4j_import:/var/lib/neo4j/import
      - neo4j_plugins:/plugins

volumes:
  neo4j_data:
  neo4j_logs:
  neo4j_import:
  neo4j_plugins:

Step 2: Configure Environment Variables

In the environment section, we specify the necessary environment variables for Neo4j:

  • NEO4J_AUTH=neo4j/securepassword: Sets the authentication for the Neo4j instance. You can replace securepassword with your desired password.

  • NEO4J_dbms_memory_pagecache_size=4G: Sets the page cache size.

  • NEO4J_dbms_memory_heap_initial__size=2G: Sets the initial heap memory size.

  • NEO4J_dbms_memory_heap_max__size=4G: Sets the maximum heap memory size.


Step 3: Map Ports

We map the container ports to the host machine ports to access the Neo4j Browser and the Bolt protocol:

  • 7474:7474: HTTP port for the Neo4j Browser and API.

  • 7687:7687: Bolt port for database connections.


Step 4: Define Volumes

Volumes are specified to persist data, logs, imports, and plugins:

  • neo4j_data: Stores the database data.

  • neo4j_logs: Stores the log files.

  • neo4j_import: Directory for importing data.

  • neo4j_plugins: Stores plugins.


Step 5: Start the Neo4j Service

Navigate to the directory containing your docker-compose.yml file and run the following command:

docker-compose up -d

The -d flag runs the services in detached mode. Docker Compose will pull the necessary images and start the Neo4j container.


Step 6: Access the Neo4j Browser

Once the container is up and running, you can access the Neo4j Browser by navigating to http://localhost:7474 in your web browser. Log in using the username neo4j and the password you specified in the docker-compose.yml file.


Step 7: Verify the Setup

To verify that everything is working correctly, you can run some basic Cypher queries in the Neo4j Browser. For example, create a sample node:

CREATE (n:Person {name: 'John Doe', age: 29})
RETURN n

Conclusion

Using Docker Compose to run Neo4j provides a streamlined and efficient way to manage your graph database instances. With just a few lines of configuration in the docker-compose.yml file, you can set up, run, and scale your Neo4j environment.

Feel free to explore further configurations and optimizations based on your specific use case. Happy graphing!

57 views0 comments

Comments


bottom of page