# Setting up dgraph in a test environment

**URL:** <https://discuss.dgraph.io/t/setting-up-dgraph-in-a-test-environment/3327>\
**Category:** Dgraph\
**Created:** [October 2, 2018, 9:27am UTC](https://discuss.dgraph.io/t/setting-up-dgraph-in-a-test-environment/3327 "2018-10-02T09:27:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aryzing](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/aryzing/32/1146_2.png) [@aryzing](https://discuss.dgraph.io/u/aryzing)\
**Post date:** [October 2, 2018, 9:27am UTC](https://discuss.dgraph.io/t/setting-up-dgraph-in-a-test-environment/3327/1 "2018-10-02T09:27:14Z")

</div>

I’m getting ready to start integration and E2E tests for my application. In so doing, I’m trying to figure out

- The minimum number of ports I need to expose to commit a small number of queries and mutations
- Making sure that ports are set up correctly so `zero` and `server` can talk to each other.

I’ve had a look at the [ports table](https://docs.dgraph.io/deploy#ports-used-by-different-nodes), my understanding is that if the tests use a grpc client, the only port I need exposed is 9080, is this correct?

Also, please bear with me as I’m not a docker expert.

When comparing the [setup in the tour](https://tour.dgraph.io/intro/2/) with the [setup from the docs](https://docs.dgraph.io/deploy#run-using-docker), the former uses `docker exec`, and the latter `docker run`.

It is my understanding that using `docker run` will create a new container to run the server. In this case the server will need to communicate with zero through an external port exposed by the image running zero, is this correct? Does this mean that if zero is running on port 5080 within it’s image, in order for the server to talk to dgraph, this port must be exposed? The port chosen to export the internal 5080 port must then be supplied to the server by means of the `--zero` flag correct?

However, if we can get by with keeping things small, and we don’t need a separate docker image for the server, we can boot it up within the same image as `zero`'s with `docker exec` (as is done in the tutorial). In this case, do we still need to expose port 5080?

In the following command (taken form the tutorial), is the `localhost:5080` referring to the machine where docker is running, or an internal image address?

```auto
docker exec -it dgraph dgraph server --lru_mb 2048 --zero localhost:5080

```

Sorry for the long post, just trying to straighten out several ideas.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [October 2, 2018, 1:52pm UTC](https://discuss.dgraph.io/t/setting-up-dgraph-in-a-test-environment/3327/2 "2018-10-02T13:52:08Z")

</div>

What’s on the Tour is just to use for learning, more specific recommendations with Docker should follow what’s in Dgraph’s documentation or what the Docker community recommends.

> [@aryzing](#):
>
> I’ve had a look at the [ports table](https://docs.dgraph.io/deploy#ports-used-by-different-nodes), my understanding is that if the tests use a grpc client, the only port I need exposed is 9080, is this correct?

No, Dgraph needs Server and Zero. So you have to expose 5080, 9080 and 7080. And HTTP ports if gonna use Ratel and a HTTP client.

> [@aryzing](#):
>
> In this case, do we still need to expose port 5080?

Probably not, but not recommended. It is a standard of Docker’s own use. Each container running a service/binary. Leaving a “fatty” container is not recommended by Docker community. And it does not help at all, you do not lose anything in following the recommendations.

> [@aryzing](#):
>
> where docker is running, or an internal image address?

It can binds locally.

Do like the docker-compose.yml example. That one follows the recommended approach.

---

<div class="post-metadata">

**Author:** ![aryzing](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/aryzing/32/1146_2.png) [@aryzing](https://discuss.dgraph.io/u/aryzing)\
**Post date:** [October 2, 2018, 7:03pm UTC](https://discuss.dgraph.io/t/setting-up-dgraph-in-a-test-environment/3327/3 "2018-10-02T19:03:12Z")

</div>

Just as an FYI for anyone else looking into running a minimal setup (for testing purposes, for example): If you’re

- running a single container,
- and within that container you run both `zero` and `server` with their [default ports](https://docs.dgraph.io/deploy#ports-used-by-different-nodes)
- and your client is using grpc to communicate with `server`

then the only port you need to expose/publish is `9080`.

The particular setup that works for me:

**Dgraph Docker setup for testing**

```auto
docker run -p 9080:9080 --name dgraph-tests dgraph/dgraph dgraph zero
docker exec dgraph-tests dgraph server --lru_mb 4096 --zero localhost:5080

```

^^Forgive the formatting, `hljs` thinks it sql code

**Client setup, `dgraph-js`**

```auto
import * as dgraph from 'dgraph-js';
import grpc from 'grpc';

const clientStub = new dgraph.DgraphClientStub(
  'localhost:9080',
  grpc.credentials.createInsecure()
);

const dgraphClient = new dgraph.DgraphClient(clientStub);

```
