无法通过Postico连接到PostgreSQL Docker容器

时间:2019-01-07 21:57:00

标签: postgresql docker postico

我正在尝试使用Postico连接到本地计算机上的docker postgreSQL容器。

我尝试连接到0.0.0.0,localhost和127.0.0.1。每个给我以下错误:

could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

0.0.0.0给了我类似的但较小的错误:

could not connect to server: Connection refused
    Is the server running on host "0.0.0.0" and accepting
    TCP/IP connections on port 5432?

这是我的docker-compose文件:

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.23
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        databases:
          default:
            connector: postgres
            host: postgres
            port: 5432
            user: prisma
            password: prisma
            migrations: true
  postgres:
    image: postgres:10.5
    restart: always
    environment:
      POSTGRES_USER: prisma
      POSTGRES_PASSWORD: prisma
    volumes:
      - postgres:/var/lib/postgresql/data
volumes:
  postgres:

感谢Egor,找到了解决方案!我忘记在docker-compose文件中指定ports: - "5432:5432"。新秀错误;)

2 个答案:

答案 0 :(得分:1)

如果postgres版本无关紧要,请尝试将Postgres图像更改为此版本,

还要确保您在docker-compose.yml

中添加端口
postgres:
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: prisma
      POSTGRES_PASSWORD: prisma
    ports: 
     - "5432: 5432"
    volumes:
      - postgres:/var/lib/postgresql/data

P.s。刚刚更新了可读性答案

答案 1 :(得分:0)

在使用Postico连接到Docker容器中的Postgres数据库时,我也遇到了问题。

最终,我的问题是我正在运行本地Postgres数据库

我断开本地Postgres数据库的连接后,便能够使用Postico连接到我的Docker数据库。在主机设置为localhost的情况下,我使用了POSTGRES_USER文件中定义的POSTGRES_PASSWORDdocker-compose.yml和主机端口。

Connection Detail for Postico