Docker Postgres映像:主机没有pg_hba.conf条目 [英] Docker postgres image: no pg_hba.conf entry for host

查看:407
本文介绍了Docker Postgres映像:主机没有pg_hba.conf条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于DB的Docker映像(已安装了postgres),我尝试运行它,但得到了以下内容:

I have a Docker image for DB (postgres is installed) and I try to run it but I get the following:


db | 2018-11-27 08:29:28.849 UTC [2808]致命:主机 172.xxx,用户 postgres,数据库
postgres,没有SSL的
pg_hba.conf条目

db | 2018-11-27 08:29:28.849 UTC [2808] FATAL: no pg_hba.conf entry for host "172.x.x.x", user "postgres", database "postgres", SSL off

我尝试了以下操作:


  • 到更改IP并放置我当前计算机的IP

  • 设置Postgres时: echo -e托管所有0.0.0.0/0信任 我说了

  • To change the IP and put my current machine's ip
  • When setting up Postgres: echo -e "host all all 0.0.0.0/0 trust" I put that

这些都不起作用。

推荐答案

我遇到了同样的问题,使我的应用程序容器与postgres容器进行通信。我通过三个步骤解决了这个问题:

I ran into the same problem getting my application container to talk to my postgres container. I fixed this with three steps:


  1. 定义docker网络的网络IP地址范围



# +----------------------+
# |  docker-compose.yml  |
# +----------------------+
networks:
  my_docker_network:
    driver: bridge
    ipam:
      config:
        - subnet: 10.5.0.0/16




  1. 将postgres pg_hba.conf文件中的相同网络ip地址范围白名单



# +---------------+
# |  pg_hba.conf  |
# +---------------+
# TYPE  DATABASE        USER            ADDRESS                 METHOD
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             10.5.0.0/16             trust

我使用了 trust 来避免身份验证的麻烦,但是您可以指定 md5 cert ,或任何其他有效的身份验证方法。

I used trust to avoid authentication hassles, but you could specify md5, cert, or any other valid authentication method.


  1. 允许postgres监听postgresql.conf文件中的外部主机



# +-------------------+
# |  postgresql.conf  |
# +-------------------+
# - Connection Settings -
listen_addresses = '*'          # what IP address(es) to listen on;

这篇关于Docker Postgres映像:主机没有pg_hba.conf条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆