Docker Compose中Hasura的两个数据库

jljoyd4f  于 2022-11-03  发布在  Docker
关注(0)|答案(1)|浏览(157)

我试图在Docker Compose中分离hasura的数据库。我的想法是有一个hasura的元数据数据库。还有一个是我的实际数据。这是我的docker-compose.yml文件。

version: "3.8"
services:
  meta:
    image: postgres
    hostname: meta
    container_name: meta
    environment:
      POSTGRES_DB: meta
      POSTGRES_USER: meta
      POSTGRES_PASSWORD: metapass
    restart: always
    volumes:
      - db_meta:/var/lib/postgresql/data
    networks:
      - backend
  data:
    image: postgres
    hostname: data
    container_name: data
    environment: 
      POSTGRES_DB: data
      POSTGRES_USER: data
      POSTGRES_PASSWORD: datapass
    restart: always
    volumes:
      - db_data:/var/lib/postgresql/data
    networks:
      - backend
  graphql-engine:
    image: hasura/graphql-engine:v2.13.0
    ports:
    - "8080:8080"
    depends_on:
    - "meta"
    - "data"
    restart: always
    environment:
      ## postgres database to store Hasura metadata
      # Database URL postgresql://username:password@hostname:5432/database
      HASURA_GRAPHQL_METADATA_DATABASE_URL: meta://meta:metapass@meta:5432/meta
      ## this env var can be used to add the above postgres database to Hasura as a data source. this can be removed/updated based on your needs
      PG_DATABASE_URL: data://data:datapass@data:5432/data
      ## enable the console served by server
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
      ## enable debugging mode. It is recommended to disable this in production
      HASURA_GRAPHQL_DEV_MODE: "true"
      HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
      ## uncomment next line to run console offline (i.e load console assets from server instead of CDN)
      # HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets
      ## uncomment next line to set an admin secret
      # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
    networks:
      - backend
volumes:
  db_data:
  db_meta:
networks: 
  backend: 
    driver: bridge

我得到{"detail":{"info":{"code":"postgres-error","error":"connection error","internal":"missing \"=\" after \"meta://meta:metapass@meta:5432/meta\" in connection info string\n","path":"$"},"kind":"catalog_migrate"},"level":"error","timestamp":"2022-10-24T14:16:06.432+0000","type":"startup"}
我想这个问题和主机名有关。但是我不知道怎么解决。有什么办法吗?

xdyibdwo

xdyibdwo1#

我已经尝试了很多,所以现在我的解决方案看起来是这样的。我注意到volumes delete使它更容易开发。数据库URL的开头必须以postgresql://开头。正如@landercy已经说过的那样。

version: "3.8"
services:

  meta:
    image: postgres
    container_name: meta
    restart: always
    volumes:
      - db_meta:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: meta_user
      POSTGRES_PASSWORD: meta_password
      POSTGRES_DB: meta_db

  data:
    image: postgres
    container_name: data
    restart: always
    volumes:
      - db_data:/var/lib/postgresql/data
    environment: 
      POSTGRES_USER: data_user
      POSTGRES_PASSWORD: data_password
      POSTGRES_DB: data_db
    ports:
    - 5432:5432

  graphql-engine:
    image: hasura/graphql-engine
    depends_on:
    - "meta"
    - "data"
    restart: always
    environment:
      ## postgres database to store Hasura metadata
      # Database URL postgresql://username:password@hostname:5432/database
      HASURA_GRAPHQL_METADATA_DATABASE_URL: postgresql://meta_user:meta_password@meta:5432/meta_db
      ## this env var can be used to add the above postgres database to Hasura as a data source. this can be removed/updated based on your needs
      PG_DATABASE_URL: postgresql://data_user:data_password@data:5432/data_db
      ## enable the console served by server
      HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
      ## enable debugging mode. It is recommended to disable this in production
      HASURA_GRAPHQL_DEV_MODE: "true"
      HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
      ## uncomment next line to run console offline (i.e load console assets from server instead of CDN)
      # HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets
      ## uncomment next line to set an admin secret
      # HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
    ports:
    - "8080:8080"

volumes:
  db_data:
  db_meta:

相关问题