Avoid losing data when restarting docker

I use Dgraph Cloud in production, but for development I spin up dgraph using docker-compose. My problem is that when I run docker-compose down then docker-compose up -d, all the data (including the schema) is gone. I want to be able to persist the data across restarting docker.

I think the solution involves changing the volumes configuration, but I don’t know how to do that properly. Any help, guidance, or resources would be appreciated!

(For reference I’m running on Windows 11)

My config:

version: "3.8"
services:
  zero1:
    image: dgraph/dgraph:v23.1.0
    working_dir: /data/zero1
    ports:
      - 5080:5080
      - 6080:6080
    labels:
      cluster: test
      service: zero1
    volumes:
      - ~/dgraph:/dgraph
    restart: on-failure
    command: dgraph zero
      --logtostderr -v=2
      --bindall
      --expose_trace
      --profile_mode block
      --block_rate 10
      --my=zero1:5080
  alpha1:
    image: dgraph/dgraph:v23.1.0
    working_dir: /data/alpha1
    volumes:
      - ~/dgraph:/dgraph
    ports:
      - 8080:8080
      - 9080:9080
    labels:
      cluster: test
      service: alpha1
    restart: on-failure
    command: dgraph alpha 
      --zero=zero1:5080
      --expose_trace
      --profile_mode block
      --block_rate 10
      --logtostderr 
      -v=2
      --my=alpha1:7080
      --bindall
      --security whitelist=0.0.0.0/0
      --graphql lambda_url=http://lambda:8686/graphql-worker

  lambda:
    image: dgraph/dgraph-lambda
    labels:
      cluster: test
    ports:
      - 8686:8686
    depends_on:
      - alpha1
    environment:
      DGRAPH_URL: http://alpha1:8080
    volumes:
      - type: bind
        source: ./dist/lambdas.js # for webpack
        target: /app/script/script.js
        read_only: true

It should be

working_dir: /dgraph/data/zero1
working_dir: /dgraph/data/alpha1

1 Like

Tested and it works now.

Thanks much. :pray: :pray: :pray: :pray: :pray:

I’ve been banging my head against this for longer than I’d care to admit.

1 Like