Can I run multiple alphas in one host with docker compose?

Hi, I’m could run my docker-compose yml with one instance of alpha and zero, my question is how can I run multiple alphas and zeros (say 3 alphas and 3 zeros) in one host (server). I made little cahnges to the docker-compose.yml example you procided so this is my yml file.

version: '3.2'
services:
  zero:
    image: dgraph/dgraph:latest
    volumes:
      - dgraphdb:/dgraph
    ports:
      - 5080:5080
      - 6080:6080
    restart: on-failure
    command: dgraph zero --my=zero:5080
    networks:
      - dgraph-net
  alpha1:
    image: dgraph/dgraph:latest
    hostname: "alpha1"
    restart: on-failure
    ports:
      - 8012:8080
      - 8011:9080
    volumes:
      - dgraphdb:/dgraph
    networks:
      - dgraph-net
    command: dgraph alpha --my=alpha1:7080 --zero=zero:5080 --whitelist 172.17.0.0:172.30.0.0,192.168.1.1
  alpha2:
    image: dgraph/dgraph:latest
    hostname: "alpha2"
    restart: on-failure
    ports:
      - 8213:8081
      - 8214:9081
    volumes:
      - dgraphdb:/dgraph
    networks:
      - dgraph-net
    command: dgraph alpha --my=alpha2:7081 --zero=zero:5080 -o 1 --whitelist 172.17.0.0:172.30.0.0,192.168.1.1
  alpha3:
    image: dgraph/dgraph:latest
    hostname: "alpha3"
    restart: on-failure
    ports:
      - 8215:8082
      - 8216:9082
    volumes:
      - dgraphdb:/dgraph
    networks:
      - dgraph-net
    command: dgraph alpha --my=alpha3:7082 --zero=zero:5080 -o 2 --whitelist 172.17.0.0:172.30.0.0,192.168.1.1

  ratel:
    image: dgraph/dgraph:latest
    command: dgraph-ratel
    ports:
      - 8010:8000
    networks:
      - dgraph-net
volumes:
  dgraphdb: ~
networks:
  miauth-net:
  dgraph-net:

But when I run this it returns the error:

...
alpha1_1  | E1007 14:39:17.852708      15 groups.go:1137] Error during SubscribeForUpdates for prefix "\x00\x00\x15dgraph.graphql.schema\x00": Unable to find any servers for group: 1. closer err: <nil>
alpha1_1  | I1007 14:39:17.951955      15 pool.go:160] CONNECTING to zero:5080
...
alpha2_1  | Cannot acquire directory lock on "w".  Another process is using this Badger database.
...
alpha3_1  | Cannot acquire directory lock on "w".  Another process is using this Badger database.

(an extended log is here)

How can I setup properly multiple instances of alpha and zeros in one host (server or local pc) ?

My guess would be that you need separate volumes for your alpha processes.

1 Like

Yes, unless you have a volume for each instance, you should start Dgraph like:

dgraph alpha --my=alpha1:7080 --zero=zero:5080 -w=./wall0 -p=./posting0
dgraph alpha --my=alpha2:7081 --zero=zero:5080 -o 1 -w=./wall1 -p=./posting1
dgraph alpha --my=alpha3:7082 --zero=zero:5080 -o 2 -w=./wall2 -p=./posting2

having a separate volume for each alpha means I will get 3 databases? or one database with these 3 volumes?

No, Dgraph is a cluster configuration. The Cluster itself is your database.

The volumes will store the data that Dgraph needs to provide its services. Each Dgraph instance has its own context, so you shouldn’t mix them. That’s why you get the error Cannot acquire directory lock on "w".

Cheers.

Hi @anargu

Let me try a simplified explanation. Dear dgraph devs, if I get any details wrong, feel free to correct them.

With distributed databases, it usually works like this:

  1. Data is distributed (hence the name) to multiple nodes, each node holds only parts of the data.
  2. For data safety and fault tolerance reasons, data is also replicated, so your cluster will store data multiple times.

Let’s say you have three nodes and a replication factor of two. That means:

  1. Each data point is stored twice, on two different nodes.
  2. The data is distributed (“sharded”) among the nodes as evenly as possible.
  3. With 3 nodes and an RF of 2, each node holds 2/3 of the total data.
  4. During queries, work can be parallelized and given to multiple nodes, speeding things up.
  5. If you loose one node, temporarely or permanently, all your data is still there and the database can continue to serve requests.
2 Likes