D.3. Highly Available mode on Docker

This section describes how to run Neo4j in Highly Available mode, in a Docker container.

In order to run Neo4j in HA mode under Docker you need to wire up the containers in the cluster so that they can talk to each other. Each container must have a network route to each of the others and the NEO4J_ha_host_coordination, NEO4J_ha_host_data and NEO4J_ha_initial__hosts environment variables must be set accordingly:

Within a single Docker host, this can be achieved as follows:

docker network create --driver=bridge cluster

docker run --name=instance1 --detach --publish=7474:7474 --publish=7687:7687 --net=cluster --hostname=instance1 \
    --volume=$HOME/neo4j/logs1:/logs \
    --env=NEO4J_dbms_mode=HA --env=NEO4J_ha_server__id=1 \
    --env=NEO4J_ha_host_coordination=instance1:5001 --env=NEO4J_ha_host_data=instance1:6001 \
    --env=NEO4J_ha_initial__hosts=instance1:5001,instance2:5001,instance3:5001 \
    --env=NEO4J_ACCEPT_LICENSE_AGREEMENT=yes \
    neo4j:3.4-enterprise

docker run --name=instance2 --detach --publish=7475:7474 --publish=7688:7687 --net=cluster --hostname=instance2 \
    --volume=$HOME/neo4j/logs2:/logs \
    --env=NEO4J_dbms_mode=HA --env=NEO4J_ha_server__id=2 \
    --env=NEO4J_ha_host_coordination=instance2:5001 --env=NEO4J_ha_host_data=instance2:6001 \
    --env=NEO4J_ha_initial__hosts=instance1:5001,instance2:5001,instance3:5001 \
    --env=NEO4J_ACCEPT_LICENSE_AGREEMENT=yes \
    neo4j:3.4-enterprise

docker run --name=instance3 --detach --publish=7476:7474 --publish=7689:7687 --net=cluster --hostname=instance3 \
    --volume=$HOME/neo4j/logs3:/logs \
    --env=NEO4J_dbms_mode=HA --env=NEO4J_ha_server__id=3 \
    --env=NEO4J_ha_host_coordination=instance3:5001 --env=NEO4J_ha_host_data=instance3:6001 \
    --env=NEO4J_ha_initial__hosts=instance1:5001,instance2:5001,instance3:5001 \
    --env=NEO4J_ACCEPT_LICENSE_AGREEMENT=yes \
    neo4j:3.4-enterprise

See the Section D.8.1, “Set up an HA cluster” for more details of Neo4j Highly Available mode.