Dgraph http port forwarding using traefik

OK, guys I know this is not really Dgraph specifically, but following every tutorial I have found, I can’t seem to get graphql endpoint to be served on a different port, for instance 8081.

Here is a regular working docker-compose.yml on port 8080 normally.

version: "3.2"
services:
  reverse-proxy:
    image: traefik:v2.2
    command:
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.dgraph.address=:"8080"
    ports:
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
  zero:
    image: dgraph/dgraph:master
    volumes:
      - /dgraph/data:/dgraph
    restart: always
    command: dgraph zero --my=zero:5080
  alpha:
    image: dgraph/dgraph:master
    volumes:
      - /dgraph/data:dgraph
    labels:
      - "traefik.enable=true"
      - "traefik.http.middlewars.adminIps.ipwhitelist.sourcerange=1.1.1.1" #My actual ip address
      - "traefik.htto.routers.alpha.rule=Host(`mydomain.com`) && Path(`/graphql`)"
      - "traefik.http.routers.all.rule=Host(`mydomain.com`)"
      - "[email protected]"
      - "traefik.http.routers.all.entrypoints=dgraph"
    restart: always
    command: dgraph alpha --my=alpha:7080 --zero=zero:5080 --whitelist 172.0.0.0:172.254.254.254

I have tried by just changing the received port:

  - "8081:8080"

but that does not even seem to open the port 8081. Next I reversed that change and tried to make everything 8081 on the received and then add a load balancer on the received image with lable:

  - "--entrypoints.dgraph.address=:"8081"
  ...
  - "8081:8081"

  # after "traefik.http.routers.all.entrypoints=dgraph"
  - "traefik.http.services.alpha.loadbalancer.server.port=8080"

But again this seems to not open port 8081.


Does anyone have experience with traefik that can offer some pointers of where I am going wrong? I am wanting to do some more advanced options by pointing 80 at 443 which I want to secure with letsencrypt and then point that at 8080 graphql endpoint. But in order to do all of this, I need to be able to do this simple port forwarding and figured 8081->8080 would be an easy task. Well, so much for that :frowning:

Again, I know not specifically Dgraph (at least I don’t think) so if I need to post elsewhere I will.

Do you mean Dgraph port or Traefik port?

If you wanna expose the port 8081 to the public, you have to set this port on Traefik. I see that it is running only in 8080. You can set both or more. You can’t expose (I mean, use in the reverse proxy) a port that Traefik doesn’t manage.

I think it should be like this

services:
  reverse-proxy:
    image: traefik:v2.2
    command:
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.dgraph.address=:"8080"
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
      - "8081:8081"
  alpha:
    image: dgraph/dgraph:master
    volumes:
      - /dgraph/data:dgraph
    labels:
     (...)
    ports:
      - "8081:8080" #If that doesn't work, it would be easier to use port offset

Ok, I will try this this evening. I spent way too much time not getting anywhere last night.

I think this is possible cuz I can do it on k8s doing 8080 => 80 - should be the same logic, go check out their community. There are several users there that might have been on your situation.

But a second thought (I haven’t used Docker in day to day for a long time) I think that changing the PORT on the container will not help. Maybe you should actually use offset.

OR, you can use NGINX container to do this for you. You can have an NGINX instance that runs Dgraph that forwards the port 8080 to 8081 internally. So the container will actually have the port you need.