postgresql - 即使提供了所需的网络设置,也无法通过 docker 连接到 Postgresql
问题描述
我已经在本地安装了 postgresql 并想将我的 docker 实例连接到它。
docker run 命令包括:
run:
IMAGE=$(IMAGE) CONFIG=$(config) docker-compose -f docker-compose.yml up -d
local:
@make build
@echo "\nCreate docker container.."
@make run config=$(config)
@echo "\n$(GREEN)Done.$(NO_COLOR)\n"
@echo "Try pallet at http://localhost:8080."
@echo "and flower at http://localhost:5555."
POSTGRES_HOST=192.168.0.142:5432
POSTGRES_PORT=5432
POSTGRES_CREDS=pallet:pallet
这些分别是来自 docker 和环境文件的设置。
docker build 成功,但出现以下错误:
sqlalchemy.exc.InvalidRequestError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (psycopg2.OperationalError) FATAL: no pg_hba.conf entry for host "172.21.0.2", user "pallet", database "airflow", SSL on
FATAL: no pg_hba.conf entry for host "172.21.0.2", user "pallet", database "airflow", SSL off
我已经更改了配置文件:
# - Connection Settings -
listen_addresses = '0.0.0.0' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#superuser_reserved_connections = 3 # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
# (change requires restart)
#bonjour = off # advertise server via Bonjour
# (change requires restart)
#bonjour_name = '' # defaults to the computer name
# (change requires restart)
# - Security and Authentication -
#authentication_timeout = 1min # 1s-600s
ssl = true # (change requires restart)
#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
# (change requires restart)
#ssl_prefer_server_ciphers = on # (change requires restart)
#ssl_ecdh_curve = 'prime256v1' # (change requires restart)
ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem' # (change requires restart)
ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key' # (change requires restart)
#ssl_ca_file = '' # (change requires restart)
#ssl_crl_file = '' # (change requires restart)
#password_encryption = on
#db_user_namespace = off
#row_security = on
# GSSAPI using Kerberos
#krb_server_keyfile = ''
#krb_caseins_users = off
# - TCP Keepalives -
# see "man 7 tcp" for details
#tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds;
# 0 selects the system default
#tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds;
# 0 selects the system default
#tcp_keepalives_count = 0 # TCP_KEEPCNT;
# 0 selects the system default
并且已经添加了这些行:
#hostssl "airflow" "pallet" '*' md5
#hostnossl "airflow" "pallet" '*' md5
host all all '*' trust
是的,我取消了注释,然后在文件中运行了它们中的每一个/etc/postgresql/9.5/main/pg_hba.conf
解决方案
将以下行添加到pg_hba.conf
host all all all trust
或者更具体,如果你喜欢。
错误消息非常清楚地表明不允许使用主机 ip。
推荐阅读
- css - 在 CSS 中的不同字符上设置文本换行的优先级
- regex - 将包含 Unicode 换行符的行与 Notepad++ 正则表达式中的点模式匹配
- reactjs - 为了响应 API,React.js,向数组中的对象添加属性的更好方法是什么?
- python - 如何将此字典列表转换为 csv 文件
- eclipse - 每次我需要在 Mac 上清理和构建我的需求软件项目时
- c++ - 声明 `using namespace C;` 对于证明 [namespace.udir]/3 中的示例中显示的结果是必不可少的
- c# - .NET 应用程序在上传大文件时崩溃
- sql - 主查询未读取子查询结果集
- java - 需要了解创建对象和更新引用的 java 8 行为
- shopify - Shopify dev 中未加载嵌套资产