Best way to run local Dgraph executable in Docker

Hi!

I’m new to Go, Dgraph, and Docker, so this may be a bit of a silly question (I apologize in advance).

I created a PR to add a whitelist feature on admin/export (Added IP whitelist for admin/export by armcburney · Pull Request #2233 · dgraph-io/dgraph · GitHub) from an issue created recently on GitHub (IP range whitelist for admin/export · Issue #1924 · dgraph-io/dgraph · GitHub).

I’m not certain what the best way to test this feature is. Pawan suggested that Docker would be a good approach, but I’m not sure what it would entail testing this in Docker using my local executable.

Any advice would be greatly appreciated. Again, I apologize if this is a silly question.

All the best,

Andrew

There is a script at contrib/nightly/build.sh. When you run that, it builds the binary and embeds it in a docker image with tag master. Then you can use it to run dgraph by following the instructions at https://tour.dgraph.io/intro/2/. The only difference being that you would use the master tag. Also, you don’t need to pull the image, as you already have it locally.

So first instruction becomes

docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 -p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph dgraph/dgraph:master dgraph zero
docker exec -it dgraph dgraph server --memory_mb 2048 --zero localhost:5080

Now if you try to run export from outside the Docker container running zero and server (i.e. from your host machine), you should get an error.

Hi Pawan,

I tried to run the contrib/nightly/build.sh, but ran into the problem:

./contrib/nightly/build.sh: line 61: pushd: /Users/andrew.mcburney/go/src/github.com/dgraph-io/ratel: No such file or
 directory 

I searched for github.com/dgraph-io/ratel, but was unable to find the repository on the dgraph organization. Is it a private repository?

All the best,
Andrew

Yeah, it is a private repo. I have made the part about building Ratel optional in master. Can you pull master and try again?

Hi Pawan,

My apologies for the lack of communication. These past few weeks I was very busy, and had to put this Pull Request on hold. I’ve been having trouble building and running the container and was hoping to get some help debugging. Like I said before, I’m relatively new to docker, so I apologize if I’m missing something obvious.

I have the reproducible steps below:

Input

# ~/go/src/github.com/dgraph-io/dgraph
./contrib/nightly/build.sh

Output

dgraph git/whitelist*
❯ ./contrib/nightly/build.sh
~/go/src/github.com/dgraph-io/dgraph/dgraph ~/go/src/github.com/dgraph-io/dgraph
Building dgraph binary for darwin
# github.com/dgraph-io/dgraph/dgraph
ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in type..eqfunc.[101]interface {} from /var/folders/4p/0shw95953cd54pckwf_k_nrr0000gn/T/go-link-205319190/go.o. To fix th
is warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
~/go/src/github.com/dgraph-io/dgraph

Size of files after  strip: 30M /tmp/dgraph-build

Creating tar file
a .
a ./dgraph

Size of tar file: 9.1M  dgraph-darwin-amd64.tar.gz
Sending build context to Docker daemon  308.3MB
Step 1/8 : FROM ubuntu:16.04
 ---> f975c5035748
Step 2/8 : MAINTAINER Dgraph Labs <contact@dgraph.io>
 ---> Using cache
 ---> b893607b40b8
Step 3/8 : RUN mkdir /dgraph     && apt-get update     && apt-get install -y --no-install-recommends ca-certificates curl     && rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> d0a7fdd796cf
Step 4/8 : ADD dgraph-build /usr/local/bin
 ---> Using cache
 ---> 94e621e52f80
Step 5/8 : EXPOSE 8080
 ---> Using cache
 ---> c359f8c014f0
Step 6/8 : EXPOSE 9080
 ---> Using cache
 ---> f8c3de8da666
Step 7/8 : WORKDIR /dgraph
 ---> Using cache
 ---> 76e0a7273f3a
Step 8/8 : CMD ["dgraph"] # Shows the dgraph version and commands available.
 ---> Using cache
 ---> 45f770de0163
Successfully built 45f770de0163
Successfully tagged dgraph/dgraph:master
cd && mkdir dgraph

Input

docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 -p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph dgraph/dgraph:master dgraph zero

Output

standard_init_linux.go:195: exec user process caused "exec format error"

Input

# in another terminal
docker exec -it dgraph dgraph server --memory_mb 2048 --zero localhost:5080

Output

Error: No such container: dgraph

I also tried with [1] and [2], but it still couldn’t find the containers.

[1]

docker exec -it dgraph/dgraph:master dgraph server --memory_mb 2048 --zero localhost:5080

[2]

docker exec -it ~/dgraph:/dgraph dgraph server --memory_mb 2048 --zero localhost:5080

Any help would be greatly appreciated! Thank you!

The problem is that the binary is built for OSX but docker container is essentially running Linux and requires binaries built on Linux. You could try this on a Linux machine if you have one or we can merge your PR in and I can test it for you.

Another method is that you download the dgraph code on a virtual machine (or a docker container) and run it but I can understand that would be tricky if you are not well versed with the technology.