Connecting YugabyteDB to nakama in docker-compose

177 views Asked by At

[Question posted by a user on YugabyteDB Community Slack]

I have setup YugabyteDB and nakama (server for realtime social and web & mobile game apps) docker containers. Both work and I can query yugabytedb through DBeaver and now i wanted it to make connection with nakama server.

In nakama compose they have given example for cockroachdb and postgresql but not for yugabyte specifically. Here i have mentioned docker compose where they have given database configuration setup for postgresql. I want some help for yugabyte configuration:

version: '3'
services:
  postgres:
    container_name: postgres
    image: postgres:9.6-alpine
    environment:
      - POSTGRES_DB=nakama
      - POSTGRES_PASSWORD=localdb
    volumes:
      - data:/var/lib/postgresql/data
    expose:
      - "8080"
      - "5432"
    ports:
      - "5432:5432"
      - "8080:8080"
  nakama:
    container_name: nakama
    image: heroiclabs/nakama:3.12.0
    entrypoint:
      - "/bin/sh"
      - "-ecx"
      - >
        /nakama/nakama migrate up --database.address postgres:localdb@postgres:5432/nakama &&
        exec /nakama/nakama --name nakama1 --database.address postgres:localdb@postgres:5432/nakama --logger.level DEBUG --session.token_expiry_sec 7200        
    restart: always
    links:
      - "postgres:db"
    depends_on:
      - postgres
    volumes:
      - ./:/nakama/data
    expose:
      - "7349"
      - "7350"
      - "7351"
    ports:
      - "7349:7349"
      - "7350:7350"
      - "7351:7351"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:7350/"]
      interval: 10s
      timeout: 5s
      retries: 5
volumes:
  data:
1

There are 1 answers

0
dh YB On BEST ANSWER

First, remove the postgres container and add the following to that start a single-node cluster (one container is for a tserver and another is for a master). You can bump up the yugabytedb version:

yb-master:
      image: yugabytedb/yugabyte:2.12.1.0-b41
      container_name: yb-master-n1
      volumes:
      - yb-master-data-1:/mnt/master
      command: [ "/home/yugabyte/bin/yb-master",
                "--fs_data_dirs=/mnt/master",
                "--webserver_port=7001",
                "--master_addresses=yb-master-n1:7100",
                "--rpc_bind_addresses=yb-master-n1:7100",
                "--replication_factor=1",
                "--ysql_num_shards_per_tserver=1"]
      ports:
      - "7001:7001"
      environment:
        SERVICE_7001_NAME: yb-master

  yb-tserver:
      image: yugabytedb/yugabyte:2.12.1.0-b41
      container_name: yb-tserver-n1
      volumes:
      - yb-tserver-data-1:/mnt/tserver
      - ./hasura/seeds:/mnt/seed_data
      command: [ "/home/yugabyte/bin/yb-tserver",
                "--fs_data_dirs=/mnt/tserver",
                "--webserver_port=9001",
                "--start_pgsql_proxy",
                "--rpc_bind_addresses=yb-tserver-n1:9100",
                "--tserver_master_addrs=yb-master-n1:7100",
                "--ysql_num_shards_per_tserver=1"]
      ports:
      - "5433:5433"
      - "9001:9001"
      environment:
        SERVICE_5433_NAME: ysql
        SERVICE_9001_NAME: yb-tserver
      depends_on:
      - yb-master

Second, replace the occurences of the postgres connection string with the following:

postgresql://yugabyte:yugabyte@yb-tserver:5433/yugabyte

This should work for you.