How to run docker-compose-ha.yaml from example

Hello guys, I am new in Dgraph
I want to try tutorial running dgraph in docker with this yaml https://github.com/dgraph-io/dgraph/blob/master/contrib/config/docker/docker-compose-ha.yml

Simple as that - i just run

docker-compose up -d

But container alpha not running with error :

Cannot acquire directory lock on "p".  Another process is using this Badger database. error: resource temporarily unavailable
Error while creating badger KV posting store

any suggestions ?

Hi @PamungkasJayuda
Actually there are too many containers on that docker-compose file for just a test on local machine. Try this one and let me know how the result:

version: '2'

networks:
  DGRAPH_NET:
    driver: bridge

services:
  zero:
    image: dgraph/dgraph:v21.03.0
    container_name: "zero-dgraph"
    volumes:
      - ./dgraph_data/zero:/dgraph
    ports:
      - 5080:5080
      - 6080:6080
    restart: "no"
    networks:
      - DGRAPH_NET
    command: dgraph zero --my=zero:5080
  alpha:
    image: dgraph/dgraph:v21.03.0
    container_name: "alpha-dgraph"
    volumes:
      - ./dgraph_data/alpha:/dgraph
    ports:
      - 8080:8080
      - 9080:9080
      - 8000:8000
    restart: "no"
    networks:
      - DGRAPH_NET
    command: dgraph alpha --my=alpha:7080 --zero=zero:5080 --security whitelist=0.0.0.0/0 --graphql "debug=true;introspection=true;extensions=true;lambda-url=http://dgraph_lambda:8686/graphql-worker;"
  dgraph_lambda:
    image: dgraph/dgraph-lambda:latest
    container_name: dgraph_lambda
    ports:
      - "8686:8686"
    environment:
      DGRAPH_URL: http://alpha:8080
    volumes:
      - ./dist/script.js:/app/script/script.js:ro
    networks:
        - DGRAPH_NET

Also add this folder to your .gitignore: dgraph_data

As far as I know, this is due to the conflict caused by multiple alpha using the same p directory. You only need to separate the data volumes of different alpha.

Here is my yaml

version: "3.2"
networks:
  dgraph:

services:
  zero1:
    image: dgraph/dgraph:v21.03.2
    volumes:
      - ./dgraph_data/zero1:/dgraph
    ports:
      - 5081:5080
      - 6081:6080
    networks:
      - dgraph
    healthcheck:
      test: ["CMD", "curl", "-IL", "localhost:6080/state"]
      interval: 10s
      start_period: 10s
      timeout: 5s
      retries: 3
    command: dgraph zero --my=zero1:5080 --replicas 3 --raft="idx=1"
  zero2:
    image: dgraph/dgraph:v21.03.2
    depends_on: 
      zero1:
        condition: service_healthy
    volumes:
      - ./dgraph_data/zero2:/dgraph
    ports:
      - 5082:5080
      - 6082:6080
    networks:
      - dgraph
    healthcheck:
      test: ["CMD", "curl", "-IL", "localhost:6080/state"]
      interval: 10s
      start_period: 10s
      timeout: 5s
      retries: 3
    command: dgraph zero --my=zero2:5080 --replicas 3 --peer zero1:5080 --raft="idx=2"
  zero3:
    image: dgraph/dgraph:v21.03.2
    depends_on: 
      zero2:
        condition: service_healthy
    volumes:
      - ./dgraph_data/zero3:/dgraph
    ports:
      - 5083:5080
      - 6083:6080
    networks:
      - dgraph
    healthcheck:
      test: ["CMD", "curl", "-IL", "localhost:6080/state"]
      interval: 10s
      start_period: 10s
      timeout: 5s
      retries: 3
    command: dgraph zero --my=zero3:5080 --replicas 3 --peer zero1:5080 --raft="idx=3"
  alpha1:
    image: dgraph/dgraph:v21.03.2
    depends_on: 
      zero3:
        condition: service_healthy
    volumes:
      - ./dgraph_data/alpha1:/dgraph
    ports:
      - 8081:8080
      - 9081:9080
    networks:
      - dgraph
    healthcheck:
      test: ["CMD", "curl", "-IL", "localhost:8080"]
      interval: 10s
      start_period: 10s
      timeout: 5s
      retries: 3
    command: dgraph alpha --my=alpha1:7080 --zero=zero1:5080,zero2:5080,zero3:5080
      --security "whitelist=0.0.0.0/0"
      --telemetry "reports=false; sentry=false;"
  alpha2:
    image: dgraph/dgraph:v21.03.2
    depends_on: 
      alpha1:
        condition: service_healthy
    volumes:
      - ./dgraph_data/alpha2:/dgraph
    ports:
      - 8082:8080
      - 9082:9080
    networks:
      - dgraph
    healthcheck:
      test: ["CMD", "curl", "-IL", "localhost:8080"]
      interval: 10s
      start_period: 10s
      timeout: 5s
      retries: 3
    command: dgraph alpha --my=alpha2:7080 --zero=zero1:5080,zero2:5080,zero3:5080
      --security "whitelist=0.0.0.0/0"
      --telemetry "reports=false; sentry=false;"
  alpha3:
    image: dgraph/dgraph:v21.03.2
    depends_on: 
      alpha2:
        condition: service_healthy
    volumes:
      - ./dgraph_data/alpha3:/dgraph
    ports:
      - 8083:8080
      - 9083:9080
    networks:
      - dgraph
    healthcheck:
      test: ["CMD", "curl", "-IL", "localhost:8080"]
      interval: 10s
      start_period: 10s
      timeout: 5s
      retries: 3
    command: dgraph alpha --my=alpha3:7080 --zero=zero1:5080,zero2:5080,zero3:5080
      --security "whitelist=0.0.0.0/0"
      --telemetry "reports=false; sentry=false;"
  alpha4:
    image: dgraph/dgraph:v21.03.2
    depends_on: 
      alpha3:
        condition: service_healthy
    volumes:
      - ./dgraph_data/alpha4:/dgraph
    ports:
      - 8084:8080
      - 9084:9080
    networks:
      - dgraph
    healthcheck:
      test: ["CMD", "curl", "-IL", "localhost:8080"]
      interval: 10s
      start_period: 10s
      timeout: 5s
      retries: 3
    command: dgraph alpha --my=alpha4:7080 --zero=zero1:5080,zero2:5080,zero3:5080
      --security "whitelist=0.0.0.0/0"
      --telemetry "reports=false; sentry=false;"
  alpha5:
    image: dgraph/dgraph:v21.03.2
    depends_on: 
      alpha4:
        condition: service_healthy
    volumes:
      - ./dgraph_data/alpha5:/dgraph
    ports:
      - 8085:8080
      - 9085:9080
    networks:
      - dgraph
    healthcheck:
      test: ["CMD", "curl", "-IL", "localhost:8080"]
      interval: 10s
      start_period: 10s
      timeout: 5s
      retries: 3
    command: dgraph alpha --my=alpha5:7080 --zero=zero1:5080,zero2:5080,zero3:5080
      --security "whitelist=0.0.0.0/0"
      --telemetry "reports=false; sentry=false;"
  alpha6:
    image: dgraph/dgraph:v21.03.2
    depends_on: 
      alpha5:
        condition: service_healthy
    volumes:
      - ./dgraph_data/alpha6:/dgraph
    ports:
      - 8086:8080
      - 9086:9080
    networks:
      - dgraph
    healthcheck:
      test: ["CMD", "curl", "-IL", "localhost:8080"]
      interval: 10s
      start_period: 10s
      timeout: 5s
      retries: 3
    command: dgraph alpha --my=alpha6:7080 --zero=zero1:5080,zero2:5080,zero3:5080
      --security "whitelist=0.0.0.0/0"
      --telemetry "reports=false; sentry=false;"
  ratel:
    image: dgraph/ratel:v21.03.2
    ports:
      - 8000:8000
    networks:
      - dgraph
    healthcheck:
      test: ["CMD", "netstat", "-plnt", "|", "grep", ":8000"]
      interval: 10s
      start_period: 10s
      timeout: 5s
      retries: 3
    command: dgraph-ratel