我目前正在使用Prisma和Postgres数据库做一个应用程序,但无法将数据库连接到Navicat。我是docker的初学者,不完全了解服务的工作方式。我当前的docker-compose.yml

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.8
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        # managementApiSecret: my-secret
        databases:
          default:
            connector: postgres
            host: postgres
            port: 5432
            user: prisma
            password: prisma
            migrations: true
  postgres:
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: prisma
      POSTGRES_PASSWORD: prisma
    volumes:
      - postgres:/var/lib/postgresql/data
volumes:
  postgres:

我在Navicat上尝试过的是this,对我来说似乎正确,但似乎没有。

谢谢你的帮助 !

最佳答案

您需要使用ports容器的postgres属性使用port mapping:

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.8
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        # managementApiSecret: my-secret
        databases:
          default:
            connector: postgres
            host: postgres
            port: 5432
            user: prisma
            password: prisma
            migrations: true
  postgres:
    image: postgres
    restart: always
    ports:
    - "5432:5432"
    environment:
      POSTGRES_USER: prisma
      POSTGRES_PASSWORD: prisma
    volumes:
      - postgres:/var/lib/postgresql/data
volumes:
  postgres:

然后,您应该能够使用Postgres客户端(例如Navicat)连接到localhost:5432

关于docker - 使用Prisma在Navicat上插入Postgres数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51216944/

10-16 09:47