Neo4j from desktop on Windows to docker under Linux
Dou Liu

Docker

Docker is a containerization platform that enables you to create, deploy, and run applications conveniently with the help of containers. These applications work within containers, like a lightweight VM. As a results, there will be no more installation, environment or application failure errors when you try to install it on another machine.

A Docker container can use one machine, share its kernel and virtualize the OS to run more isolated processes. As a result, Docker containers are lightweight. A Docker image is like a snapshot in other types of VM environments. It is a record of a Docker container at a specific point in time.

Install Docker on Ubuntu server

Follow the instructions of Install Docker Engine on Ubuntu

Set up the repository

  1. Update the apt package index and install packages to allow apt to use a repository over HTTPS:

    sudo apt-get update
    sudo apt-get install \
        ca-certificates \
        curl \
        gnupg \
        lsb-release
  2. Add Docker’s official GPG key:

    sudo mkdir -p /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  3. Use the following command to set up the repository:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine

  1. Update the apt package index, and install the latest version of Docker Engine, containerd, and Docker Compose, or go to the next step to install a specific version:
    sudo apt-get update
    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
  2. To install a specific version of Docker Engine, list the available versions in the repo, then select and install:
    # 1. List the versions available in your repo:
    apt-cache madison docker-ce
    
    # 2. Install a specific version using the version string from the second column
    sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io docker-compose-plugin
    
    # 3. Verify that Docker Engine is installed correctly
    sudo docker run hello-world

Neo4j with Docker

Get files of database

Go to the repository and download neo4j.zip. Unzip the neo4j.zip downloaded from the github, remember its location, which will be used later.

Pull the Neo4j image

I work on the conversational agent projects using a Windows laptop. So I installed Docker 4.8.1 (78998) on my computer. To run neo4j in Docker, we do not need to create an empty docker container example and download Neo4j within the container ourselves. Thanks to the Docker Hub, which is kind of similar to Github, we can download the official docker images for almost all kinds of softwares easily, such as Neo4j. To download Neo4j on Docker, use

docker pull neo4j

, which will automatically pull the latest version of Neo4j on Docker.

Create a Neo4j container

Before we create a container, it should be noted that I used Neo4j APOC plugin to export the whole database. Thus, I also need to enable the APOC plugin when creating a new Neo4j container, so that we can import the dataset. Another important config setting is NEO4J_dbms_allow__upgrade=true, which allows the database upgrade, otherwise, the unzipped database above can not be imported automatically.

I use command below to create a Neo4j container:

docker run -p 7474:7474 -p 7687:7687 \
        --volume=$HOME/neo4j/data:/data \
        --volume=$HOME/neo4j/logs:/logs \
        --volume=$HOME/neo4j/import:/var/lib/neo4j/import \
        --volume=$HOME/neo4j/plugins:/plugins \
        --name neo4j-apoc \
        --env NEO4J_AUTH=neo4j/000000 \
        --env=NEO4J_dbms_allow__upgrade=true \
        -e NEO4J_apoc_export_file_enabled=true \
        -e NEO4J_apoc_import_file_enabled=true \
        -e NEO4J_apoc_import_file_use__neo4j__config=true \
        -e NEO4JLABS_PLUGINS=\[\"apoc\"\] \
        neo4j:latest

where $HOME/neo4j/import should be the path the exported csv file located, which is /home/d in my case. The initialization takes a while, after that, the new imported Neo4j database is up running and can be accessed.

APOC Name History

APOC was the technician and driver on board of the Nebuchadnezzar in the Matrix movie. He was killed by Cypher.

APOC was also the first bundled A Package Of Component for Neo4j in 2009.

APOC also stands for “Awesome Procedures On Cypher”

Skip the docker run every single time

Sets the docker service to start when the server starts:

sudo systemctl enable docker

Make the container auto run

docker update --restart=always <container-name>
 Comments