Separate instances of Dgraph (Docker question)

I have a question similar to these two, but I’m not able to figure it out. I’m fairly new to Docker.

I have two separate projects that are using DGraph. I’d like to set up both of my docker-compose.yml files to have them initialize their own separate containers.

My docker-compose.yml files look like this, identical except that PROJECT_NAME is replaced throughout with project-one and project-two:

version: "3.2"
services:
  zero:
    image: dgraph/dgraph:latest
    container_name: PROJECT_NAME_dgraph-zero
    volumes:
      - type: volume
        source: dgraph-PROJECT_NAME
        target: /dgraph-PROJECT_NAME
        volume:
          nocopy: true
    ports:
      - 5080:5080
      - 6080:6080
    restart: on-failure
    command: dgraph zero --my=zero:5080
  server:
    container_name: PROJECT_NAME_dgraph-server
    image: dgraph/dgraph:latest
    volumes:
      - type: volume
        source: dgraph-PROJECT_NAME
        target: /dgraph-PROJECT_NAME
        volume:
          nocopy: true
    ports:
      - 8667:8080
      - 9080:9080
    restart: on-failure
    command: dgraph server --my=server:7080 --lru_mb=2048 --zero=zero:5080
  ratel:
    container_name: PROJECT_NAME_dgraph-ratel
    image: dgraph/dgraph:latest
    volumes:
      - type: volume
        source: dgraph-PROJECT_NAME
        target: /dgraph-PROJECT_NAME
        volume:
          nocopy: true
    ports:
      - 8666:8000
    command: dgraph-ratel

volumes:
  dgraph-PROJECT_NAME:

I can run docker-compose -f ./api/database/docker-compose.yml up -d in the first project and all goes well:

Creating project-one_dgraph-server ... done
Creating project-one_dgraph-zero   ... done
Creating project-one_dgraph-ratel  ... done

But, when I go to the other project and run the same command, it recreates these containers and gives them new names:

Recreating project-one_dgraph-server ... done
Recreating project-one_dgraph-zero   ... done
Recreating project-one_dgraph-ratel  ... done

This removes the project-one_dgraph... containers, and replaces them with project-two_dgraph...

How can I set this up in a way where everything remains completely separate?

Those projects are in the same Host? If so, you must to use project naming command from compose.

But be careful with PORTs. To avoid conflicts. Dgraph can get confused with multiple instances for different purposes using the same PORTs. The right thing is for you to change the offset of the Ports.

By doing this you should have a separate compose file with these new ports as well.

Ah, thanks for the heads up on offsetting the ports. I’ll take a look.

also, I wasn’t clear – these are both running on localhost. There won’t be any reason for me to be running these both at the same time.

@good-idea

Are you doing this?

This was the key for me to have both run with no issues.

Below are my two configs, which have been working for me since March.

docker-compose -f docker-compose.dev.yml -p dgraph-dev up -d
docker-compose -f docker-compose.test.yml -p dgraph-test up -d

dgraph-dev

version: "3.2"
services:
  zero:
    image: dgraph/dgraph:v1.0.5
    volumes:
      - type: volume
        source: dgraph
        target: /dgraph
        volume:
          nocopy: true
    ports:
      - 5080:5080
      - 6080:6080
    restart: on-failure
    command: dgraph zero --my=zero:5080
  server:
    image: dgraph/dgraph:v1.0.5
    volumes:
      - type: volume
        source: dgraph
        target: /dgraph
        volume:
          nocopy: true
    ports:
      - 8080:8080
      - 9080:9080
    restart: on-failure
    command: dgraph server --my=server:7080 --lru_mb=2048 --zero=zero:5080
  ratel:
    image: dgraph/dgraph:v1.0.5
    volumes:
      - type: volume
        source: dgraph
        target: /dgraph
        volume:
          nocopy: true
    ports:
      - 8000:8000
    command: dgraph-ratel

volumes:
  dgraph:

dgraph-test

version: "3.2"
services:
  zero-test:
    image: dgraph/dgraph:v1.0.5
    volumes:
      - type: volume
        source: dgraph-test
        target: /dgraph-test
        volume:
          nocopy: true
    ports:
      - 6081:6081
      - 5081:5081
    restart: on-failure
    command: dgraph zero --port_offset 1 --my=zero-test:5081
  server-test:
    image: dgraph/dgraph:v1.0.5
    volumes:
      - type: volume
        source: dgraph-test
        target: /dgraph-test
        volume:
          nocopy: true
    ports:
      - 8081:8081
      - 9081:9081
    restart: on-failure
    command: dgraph server --my=server-test:7081 --lru_mb=1024 --zero=zero-test:5081 -o 1

volumes:
  dgraph-test:
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.