Royce
Royce

Reputation: 199

Docker Compose on Crunchy Postgres and Hasura Graphql Engine - Database URL settings

If the question is unclear or there isn't enough information please let me know, as I did my best to present my issue from my understanding...

I'm trying to configure Crunchy Postgres image with Hasura GraphQL Engine, I tried changing the hostname as what the documentation suggested but it's not connecting at all to my Crunchy Postgres image.

Doc links:

https://docs.hasura.io/1.0/graphql/manual/deployment/docker/index.html

https://raw.githubusercontent.com/hasura/graphql-engine/master/install-manifests/docker-compose/docker-compose.yaml

https://hub.docker.com/r/crunchydata/crunchy-postgres/

My Docker-Compose File:

version: '3.5'

services:
  unipgdb:
    image: crunchydata/crunchy-postgres:centos7-11.1-2.3.0
    restart: always
    ports:
      - "5432:5432"
    env_file:
      - ./config/postgres/cpg-env.list
    volumes:
      - unipgdata_volume:/var/lib/postgresql/data
    networks:
      - unicausalapi

  graphql-engine:
    image: hasura/graphql-engine:v1.0.0-alpha37
    ports:
      - "8080:80"
    depends_on:
      - "unipgdb"
    restart: always
    environment:
      HASURA_GRAPHQL_DATABASE_URL: postgres://user:password@postgres:5432/unipgdb
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
      ## uncomment next line to set an access key
      # HASURA_GRAPHQL_ACCESS_KEY: mysecretaccesskey
    networks:
      - unicausalapi

  # For Hasura engine
  caddyhasura:
    build:
      context: .
      dockerfile: caddyhasura-Dockerfile
    depends_on:
      - graphql-engine
    networks:
      - unicausalapi
      - unicausalpublic
      - unicausalnetwork

volumes:
  static_volume:  # <-- declare the static volume
  media_volume:  # <-- declare the media volume
  unipgdata_volume:
      external: true

networks:
   unicausalpublic:
      external: true
   unicausalnetwork:
      external: true
   unicausalapi:
      external: true

In the Caddyfile for caddyhasura service, it is just a reverse proxy on the container graphql-engine, so it shouldn't affect my issue.

I think I'm configuring the HASURA_GRAPHQL_DATABASE_URL incorrectly with hostname because I'm not sure what to put for using crunchy-postgres:centos7 image.

I get this error in Docker Log

hasura error

How do I configure this to work with my docker-compose file using those images?

HASURA_GRAPHQL_DATABASE_URL: postgres://user:password@postgres:5432/unipgdb

Any thoughts on what to do to try and solve my problem? Thanks in advance.

Upvotes: 2

Views: 1123

Answers (1)

Shahidh
Shahidh

Reputation: 2692

Since Crunchy Postgres container's name is unipgdb, the hostname for the container will be the same. Instead of postgres as hostname, you should use this.

So, your database url will become

HASURA_GRAPHQL_DATABASE_URL: postgres://user:password@unipgdb:5432/unipgdb

If your username or password contains special characters (like $, #, @ etc.) make sure you URL encode and use them in the URL. ref: https://www.degraeve.com/reference/urlencoding.php

E.g. If password is secretPassW$or#, it should be entered as secretPassW%24or%23

Upvotes: 4

Related Questions