{"id":3381,"date":"2025-11-10T17:17:58","date_gmt":"2024-06-18T18:17:10","guid":{"rendered":""},"modified":"2025-02-02T00:46:20","modified_gmt":"2025-02-01T23:46:20","slug":"how-to-install-and-use-neo4j-graph-database-on-debian-12-using-docker-and-ansible","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/how-to-install-and-use-neo4j-graph-database-on-debian-12-using-docker-and-ansible\/","title":{"rendered":"How to Install and Use Neo4j Graph Database on Debian 12 using Docker and Ansible"},"content":{"rendered":"<p>\u00a0<\/p>\n<\/p>\n<header>\n<h1>\u00a0<\/h1>\n<p>A Comprehensive Step-by-Step Guide<\/p>\n<\/header>\n<section>\n<h2>Introduction<\/h2>\n<p>Neo4j is a highly scalable, native graph database designed to handle complex data relationships efficiently. It is widely used for applications such as social networks, recommendation engines, fraud detection, and more.<\/p>\n<p>In this guide, we will walk you through the process of installing and using Neo4j on Debian 12 using Docker and Ansible. By the end of this article, you will have a fully functional Neo4j instance running in a Dockerized environment, managed by Ansible.<\/p>\n<\/section>\n<section>\n<h2>Prerequisites<\/h2>\n<p>Before we begin, ensure that you have the following prerequisites:<\/p>\n<ul>\n<li><strong>Debian 12:<\/strong> A server running Debian 12 with root or sudo access.<\/li>\n<li><strong>Docker:<\/strong> Docker installed on your Debian 12 server. You can follow the <a href=\"https:\/\/docs.docker.com\/engine\/install\/debian\/\" target=\"_blank\" rel=\"follow\">official Docker installation guide<\/a>.<\/li>\n<li><strong>Docker Compose:<\/strong> Docker Compose installed. Follow the <a href=\"https:\/\/docs.docker.com\/compose\/install\/\" target=\"_blank\" rel=\"follow\">official Docker Compose installation guide<\/a>.<\/li>\n<li><strong>Ansible:<\/strong> Ansible installed on your local machine or control node. Follow the <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/installation_guide\/intro_installation.html\" target=\"_blank\" rel=\"follow\">official Ansible installation guide<\/a>.<\/li>\n<li><strong>Basic Knowledge:<\/strong> Familiarity with Docker, Ansible, and Linux command-line operations.<\/li>\n<\/ul>\n<\/section>\n<section>\n<h2>Step 1: Set Up Docker and Docker Compose<\/h2>\n<p>First, ensure that Docker and Docker Compose are installed and running on your Debian 12 server.<\/p>\n<h3>Install Docker<\/h3>\n<pre><code>sudo apt-get update\r\nsudo apt-get install ca-certificates curl gnupg\r\nsudo install -m 0755 -d \/etc\/apt\/keyrings\r\ncurl -fsSL https:\/\/download.docker.com\/linux\/debian\/gpg | sudo gpg --dearmor -o \/etc\/apt\/keyrings\/docker.gpg\r\nsudo chmod a+r \/etc\/apt\/keyrings\/docker.gpg\r\necho \"deb [arch=$(dpkg --print-architecture) signed-by=\/etc\/apt\/keyrings\/docker.gpg] https:\/\/download.docker.com\/linux\/debian $(. \/etc\/os-release &amp;&amp; echo \"$VERSION_CODENAME\") stable\" | sudo tee \/etc\/apt\/sources.list.d\/docker.list &gt; \/dev\/null\r\nsudo apt-get update\r\nsudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin\r\nsudo systemctl start docker\r\nsudo systemctl enable docker<\/code><\/pre>\n<h3>Install Docker Compose<\/h3>\n<pre><code>sudo curl -L \"https:\/\/github.com\/docker\/compose\/releases\/download\/v2.20.0\/docker-compose-$(uname -s)-$(uname -m)\" -o \/usr\/local\/bin\/docker-compose\r\nsudo chmod +x \/usr\/local\/bin\/docker-compose<\/code><\/pre>\n<\/section>\n<section>\n<h2>Step 2: Create a Docker Compose File for Neo4j<\/h2>\n<p>Create a directory for your Neo4j setup and navigate into it:<\/p>\n<pre><code>mkdir neo4j-setup\r\ncd neo4j-setup<\/code><\/pre>\n<p>Create a <code>docker-compose.yml<\/code> file:<\/p>\n<pre><code>version: '3.8'\r\n\r\nservices:\r\n  neo4j:\r\n    image: neo4j:latest\r\n    container_name: neo4j\r\n    restart: always\r\n    ports:\r\n      - \"7474:7474\"\r\n      - \"7687:7687\"\r\n    environment:\r\n      - NEO4J_AUTH=neo4j\/yourpassword\r\n    volumes:\r\n      - neo4j_data:\/data\r\n    networks:\r\n      - neo4j_network\r\n\r\nvolumes:\r\n  neo4j_data:\r\n\r\nnetworks:\r\n  neo4j_network:<\/code><\/pre>\n<p>This Docker Compose file defines a Neo4j service. It exposes ports 7474 (HTTP API and UI) and 7687 (Bolt protocol). Replace <code>yourpassword<\/code> with a secure password for the Neo4j instance.<\/p>\n<\/section>\n<section>\n<h2>Step 3: Deploy with Docker Compose<\/h2>\n<p>Run the following command to start the Neo4j container:<\/p>\n<pre><code>docker-compose up -d<\/code><\/pre>\n<p>This command will pull the Neo4j Docker image and start the container in detached mode.<\/p>\n<\/section>\n<section>\n<h2>Step 4: Automate with Ansible<\/h2>\n<p>To automate the deployment process, create an Ansible playbook named <code>deploy_neo4j.yml<\/code>:<\/p>\n<pre><code>---\r\n- hosts: all\r\n  become: yes\r\n  tasks:\r\n    - name: Ensure Docker is installed\r\n      apt:\r\n        name: docker-ce\r\n        state: present\r\n\r\n    - name: Ensure Docker Compose is installed\r\n      get_url:\r\n        url: https:\/\/github.com\/docker\/compose\/releases\/download\/v2.20.0\/docker-compose-$(uname -s)-$(uname -m)\r\n        dest: \/usr\/local\/bin\/docker-compose\r\n        mode: '0755'\r\n\r\n    - name: Start and enable Docker service\r\n      service:\r\n        name: docker\r\n        state: started\r\n        enabled: yes\r\n\r\n    - name: Create Neo4j setup directory\r\n      file:\r\n        path: \/opt\/neo4j-setup\r\n        state: directory\r\n\r\n    - name: Copy Docker Compose file\r\n      copy:\r\n        src: docker-compose.yml\r\n        dest: \/opt\/neo4j-setup\/docker-compose.yml\r\n\r\n    - name: Deploy Neo4j with Docker Compose\r\n      command: docker-compose up -d\r\n      args:\r\n        chdir: \/opt\/neo4j-setup<\/code><\/pre>\n<p>Run the playbook using the following command:<\/p>\n<pre><code>ansible-playbook -i your_inventory_file deploy_neo4j.yml<\/code><\/pre>\n<p>Replace <code>your_inventory_file<\/code> with the path to your Ansible inventory file.<\/p>\n<\/section>\n<section>\n<h2>Step 5: Access Neo4j Browser<\/h2>\n<p>Once the deployment is complete, open your web browser and navigate to <code>http:\/\/your_server_ip:7474<\/code>. You should see the Neo4j Browser interface. Log in using the username <code>neo4j<\/code> and the password you set in the Docker Compose file.<\/p>\n<\/section>\n<section>\n<h2>Step 6: Verify Neo4j<\/h2>\n<p>To verify that the Neo4j instance is running correctly, you can use the Neo4j Browser or the Cypher shell.<\/p>\n<h3>Using Neo4j Browser<\/h3>\n<p>Run a simple Cypher query in the Neo4j Browser to verify connectivity:<\/p>\n<pre><code>MATCH (n) RETURN n LIMIT 25;<\/code><\/pre>\n<p>This query returns up to 25 nodes from the database.<\/p>\n<h3>Using Cypher Shell<\/h3>\n<p>Access the Neo4j container and run the Cypher shell:<\/p>\n<pre><code>docker exec -it neo4j cypher-shell -u neo4j -p yourpassword<\/code><\/pre>\n<p>Run the same query to verify connectivity:<\/p>\n<pre><code>MATCH (n) RETURN n LIMIT 25;<\/code><\/pre>\n<\/section>\n<section>\n<h2>Step 7: Use Neo4j<\/h2>\n<p>Now that Neo4j is up and running, you can start using it for your graph database needs. Here are some common tasks:<\/p>\n<h3>Create Nodes and Relationships<\/h3>\n<p>Use Cypher queries to create nodes and relationships:<\/p>\n<pre><code>CREATE (a:Person {name: 'Alice'})-[:KNOWS]-&gt;(b:Person {name: 'Bob'});<\/code><\/pre>\n<h3>Query Data<\/h3>\n<p>Retrieve data using Cypher queries:<\/p>\n<pre><code>MATCH (a:Person)-[:KNOWS]-&gt;(b:Person) RETURN a, b;<\/code><\/pre>\n<h3>Import Data<\/h3>\n<p>You can import data from CSV files or other sources using the <code>LOAD CSV<\/code> command or Neo4j&#8217;s import tools.<\/p>\n<\/section>\n<section>\n<h2>Conclusion<\/h2>\n<p>In this guide, we walked you through the process of installing and using Neo4j Graph Database on Debian 12 using Docker and Ansible. By following these steps, you can easily set up a Neo4j instance for managing complex data relationships.<\/p>\n<p>Docker and Ansible make it easy to manage and automate your deployments, ensuring a smooth and consistent setup process. Whether you&#8217;re running a small project or a large-scale application, this setup provides a robust foundation for your graph database needs.<\/p>\n<\/section>\n<footer>\n<p>\u00a0<\/p>\n<\/footer>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 A Comprehensive Step-by-Step Guide Introduction Neo4j is a highly scalable, native graph database designed to handle complex data relationships efficiently. It is widely used for applications\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-3381","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/3381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=3381"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/3381\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=3381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=3381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=3381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}