Export dgraph from a docker image to a file outside of the docker image

I am very new to docker and wonder how I can get access to an export that I have completed. I am using the standard docker-compose (provided by Dgraph) and can access the export via the terminal inside the docker image, but can’t seem to interact with it outside of docker.

Here is my docker file (note this is only used for local development):

version: "3.2"
services:
  zero:
    image: dgraph/dgraph:latest
    volumes:
      - /tmp/data:/dgraph
    ports:
      - 5080:5080
      - 6080:6080
    restart: on-failure
    command: dgraph zero --my=zero:5080
  alpha:
    image: dgraph/dgraph:latest
    volumes:
      - /tmp/data:/dgraph
    ports:
      - 8080:8080
      - 9080:9080
    restart: on-failure
    command: dgraph alpha --my=alpha:7080 --zero=zero:5080 --security whitelist=0.0.0.0/0

I can then go inside the docker container by using Docker for Mac and can see the exports in the /dgraph folder.

However, how can I have this export available in the root of my project (aka outside of docker?). My goal is to export a copy of the db locally when I want to take a snapshot, and import it locally when I want to use that snapshot (I would also be using this to run tests).

What changes to I need to make to the docker-compose, or what scripts can I use to access the export inside of the image and copy it outside to my project folder?

I have not exported any data from dgraph yet, but you are saying that you can see the export data within the /dgraph folder in the container. According to your docker-compose file this folder is mapped to /tmp/data on your local machine. So have a look inside that folder, if I’m not mistaken your export data should be there.

You could map your /dgraph folder also to some other folder on your machine. I personally map it to my project folder:

volumes:
  - ./data:/dgraph
2 Likes