hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.13k stars 2.76k forks source link

How to run multiple different Hasura projects locally with Docker at the same time? #4985

Open joshuarobs opened 4 years ago

joshuarobs commented 4 years ago

I have two repos that I intend to run locally on my machine with Docker. This is on the latest Docker on the latest MacOS Catalina.

Repo 1 The first one works fine, since I just use the standard docker-compose.yaml:

docker-compose.yaml - 1

version: '3.6'
services:
  postgres:
    image: postgres:12.1
    restart: always
    volumes:
    - db_data:/var/lib/postgresql/data
  graphql-engine:
    image: hasura/graphql-engine:v1.2.1
    ports:
    - "8080:8080"
    depends_on:
    - "postgres"
    restart: always
    environment:
      HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:@postgres:5432/postgres
      HASURA_GRAPHQL_ENABLE_CONSOLE: "false" # set to "false" to disable console
      HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
      ## uncomment next line to set an admin secret
      # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey

volumes:
  db_data:

I also access the console with hasura console.

This repo runs normally as it should.

Repo 2 Obviously if I copied the exact same docker-compose.yaml from Repo 1, it won't work.

I've looked at a few other sources online to help get this work, e.g.:

I currently cannot get it to work whatsoever. Sometimes if I use a postgres port of 5442:5442 it won't work and the server keeps on restarting in Docker Dashboard. Also if I tried to manually point the Hasura server's database url to port 5442, it would complain that:

// In docker-compose.yaml
environment:
      HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:@postgres:5442/postgres

// Error in Docker Dashboard. Server keeps on restarting
graphql-engine_1 | {"type":"startup","timestamp":"2020-06-04T02:35:43.569+0000","level":"error","detail":{"kind":"db_migrate","info":{"internal":"could not connect to server: Connection refused\n\tIs the server running on host \"postgres\" (172.29.0.2) and accepting\n\tTCP/IP connections on port 5442?\n","path":"$","error":"connection error","code":"postgres-error"}}}

So I changed 5442 in the docker-compose.yaml back to 5432.

So far this is my current attempt at making it work:

docker-compose.yaml - 2

version: '3.6'
services:
  postgres:
    image: postgres:12.3
    restart: always
    volumes:
    - db_data:/var/lib/postgresql/data
    ports:
    - "5442:5432"
    environment:
      POSTGRES_HOST_AUTH_METHOD: trust
  graphql-engine:
    image: hasura/graphql-engine:v1.2.2
    ports:
    - "8090:8090"
    depends_on:
    - "postgres"
    restart: always
    environment:
      HASURA_GRAPHQL_SERVER_PORT: 8090
      HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:@postgres:5432/postgres
      HASURA_GRAPHQL_ENABLE_CONSOLE: "false" # set to "false" to disable console so we can do migrations
      HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
      ## uncomment next line to set an admin secret
      # Not needed for development since this will just slow us down
      # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
volumes:
  db_data:

Neither the graphql nor the postgres server keep on restarting, so that's a good sign. However, if I try to access the console with hasura console --console-port 9696 --endpoint http://host.docker.internal:8090 I get this error:

Running the local Hasura instance for Datbase Items on Docker (localhost:8090)
FATA[0001] version check: failed to get version from server: failed making version api call: Get http://host.docker.internal:8090/v1/version: dial tcp: lookup host.docker.internal on 10.0.0.138:53: no such host 

Has anyone managed to run 2 different hasura projects/repos at the same time on their machine locally? And if so, what docker-compose.yaml do you have for the second one?

stephanelpaul commented 4 years ago

create two independent networks with docker-compose and you could actually run it all in the same file

joshuarobs commented 4 years ago

@StephaneP Do you have any tips on how to do that? Also I can't run them from the same file since each database is its own repo and they different from each other and I need them running at the same time

tychop commented 4 years ago

I have the same requirement of running multiple Hasura instances locally in Docker at the same time.

Anyone?

white54503 commented 4 years ago

+1

abhigpt commented 3 years ago

+1. Anyone successful ? Please help

stephanelpaul commented 3 years ago

I'll share a docker-compose example.

malhotramohit commented 3 years ago

Yeah even I have the same requirement .

RobSchilderr commented 2 years ago

I'll share a docker-compose example.

reminder! haha

utkarsh-kumar-1996 commented 2 years ago

Take a look at this https://stackoverflow.com/questions/63519514/how-are-multiple-instances-of-hasura-graphql-engine-and-postgres-run-locally-via

Here is an Example: https://github.com/iosamuel/graphql-engine/blob/e3454bd00a584c030eae2a2c63905b770408fdeb/install-manifests/docker-compose/docker-compose.yaml

RobSchilderr commented 2 years ago

Take a look at this https://stackoverflow.com/questions/63519514/how-are-multiple-instances-of-hasura-graphql-engine-and-postgres-run-locally-via

Here is an Example: https://github.com/iosamuel/graphql-engine/blob/e3454bd00a584c030eae2a2c63905b770408fdeb/install-manifests/docker-compose/docker-compose.yaml

Hey, I forgot to thank you, but this was exactly what I was looking for! Thanks @utkarsh-kumar-1996 💪