Home > Software > How to Set Up Neo4j with Docker Compose: A Beginner’s Guide

How to Set Up Neo4j with Docker Compose: A Beginner’s Guide

Anastasios Antoniadis

Discover how to set up Neo4j, the leading graph database, using Docker Compose with our step-by-step guide. Simplify the deployment process and unlock the full potential of graph-based data modeling in your applications.

Docker (1)

Neo4j, a highly acclaimed graph database, offers a powerful way to model, store, and query data in terms of relationships and connections. Whether you’re building complex recommendation engines, fraud detection systems, or simply exploring graph-based data modeling, Neo4j provides the tools and flexibility needed to handle graph data effectively. Deploying Neo4j within Docker containers managed by Docker Compose can greatly simplify the setup and scalability of your Neo4j instances. This guide will walk you through deploying a Neo4j database using Docker Compose, highlighting the ease with which you can get started with graph databases.

Prerequisites

Before you begin, ensure you have the following:

  • Docker installed on your system.
  • Docker Compose installed on your system.
  • A basic understanding of Docker, Docker Compose, and graph databases.

Step 1: Create a Docker Compose File

First, create a new directory dedicated to your Neo4j project. This directory will contain your Docker Compose file (docker-compose.yml) and any additional configuration files or directories you may need.

mkdir neo4j-docker && cd neo4j-docker

Create the docker-compose.yml file:

touch docker-compose.yml

Open this file in a text editor and insert the following configuration:

version: '3'
services:
  neo4j:
    image: neo4j:latest
    container_name: neo4j
    ports:
      - "7474:7474" # HTTP
      - "7687:7687" # Bolt
    environment:
      NEO4J_AUTH: neo4j/testpassword
    volumes:
      - ./data:/data
      - ./logs:/logs
      - ./import:/var/lib/neo4j/import
      - ./plugins:/plugins

Configuration Explained:

  • image: Specifies the Docker image to use. neo4j:latest pulls the latest stable version of Neo4j.
  • container_name: Sets a custom name for your container for easier reference.
  • ports: Exposes the default Neo4j HTTP port (7474) and Bolt protocol port (7687) to the host, allowing external connections to the database.
  • environment: Defines environment variables, such as NEO4J_AUTH, to set up the initial username (neo4j) and password (testpassword) for the database.
  • volumes: Maps directories from the host to the container for data persistence (./data), logging (./logs), importing data (./import), and plugins (./plugins).

Step 2: Launch Neo4j

With your docker-compose.yml file ready, you can start your Neo4j service by running:

docker compose up -d

This command will download the necessary Docker image (if not already present) and start a Neo4j container in detached mode.

Step 3: Access Neo4j

Once the container is running, you can access the Neo4j Browser by navigating to http://localhost:7474 in your web browser. You will be prompted to log in using the credentials specified in the NEO4J_AUTH environment variable (neo4j as the username and testpassword as the password).

Conclusion

Deploying Neo4j with Docker Compose is an easy and convenient way to set up a graph database environment. Follow the steps mentioned in this guide to quickly set up a Neo4j instance for development, testing, or production purposes. Docker Compose simplifies the management of Neo4j services, and it also ensures that your database configuration is easily replicable and scalable. Whether you’re an experienced developer or new to graph databases, using Docker Compose with Neo4j can improve your data modeling capabilities and streamline your development workflow.

Anastasios Antoniadis
Follow me
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x