Postgres, RHEL and Docker



在我生命的最后4天里,我一直在与这个问题作斗争,它让我抓狂。我试图在RHEL8中部署一个使用postgresDB的服务。为了做到这一点,我将使用docker compose来部署它们。

问题是,从服务容器中,我可以ping postgres容器,但服务无法连接DB。。。

我简化了用例,并使用了一个docker compose,它使用adminer-docker映像来连接任何列出的数据库管理器,包括postgres。它在我的机器和使用ubuntu 20的测试服务器上运行得很好,但当我在RHEL 8中尝试它时,我也无法访问DB!

这是docker和docker组合版本:Docker:

Client: Docker Engine - Community
Version:           19.03.13
API version:       1.40
Go version:        go1.13.15
Git commit:        4484c46d9d
Built:             Wed Sep 16 17:02:36 2020
OS/Arch:           linux/amd64
Experimental:      false
Server: Docker Engine - Community
Engine:
Version:          19.03.13
API version:      1.40 (minimum version 1.12)
Go version:       go1.13.15
Git commit:       4484c46d9d
Built:            Wed Sep 16 17:01:11 2020
OS/Arch:          linux/amd64
Experimental:     false
containerd:
Version:          1.3.7
GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
runc:
Version:          1.0.0-rc10
GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version:          0.18.0
GitCommit:        fec3683

Docker撰写

docker-compose version 1.25.5, build 8a1c60f6
docker-py version: 4.1.0
CPython version: 3.7.5
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

操作系统

Red Hat Enterprise Linux release 8.1 (Ootpa)

我使用的实际docker组合是:

version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8080:8080

与我在其他两个系统中获得的日志相比,postgres容器的日志似乎很好:

db_1       | The files belonging to this database system will be owned by user "postgres".
db_1       | This user must also own the server process.
db_1       | 
db_1       | The database cluster will be initialized with locale "en_US.utf8".
db_1       | The default database encoding has accordingly been set to "UTF8".
db_1       | The default text search configuration will be set to "english".
db_1       | 
db_1       | Data page checksums are disabled.
db_1       | 
db_1       | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1       | creating subdirectories ... ok
db_1       | selecting dynamic shared memory implementation ... posix
db_1       | selecting default max_connections ... 100
db_1       | selecting default shared_buffers ... 128MB
db_1       | selecting default time zone ... Etc/UTC
db_1       | creating configuration files ... ok
db_1       | running bootstrap script ... ok
db_1       | performing post-bootstrap initialization ... ok
db_1       | syncing data to disk ... ok
db_1       | 
db_1       | 
db_1       | Success. You can now start the database server using:
db_1       | 
db_1       |     pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1       | 
db_1       | initdb: warning: enabling "trust" authentication for local connections
db_1       | You can change this by editing pg_hba.conf or using the option -A, or
db_1       | --auth-local and --auth-host, the next time you run initdb.
db_1       | waiting for server to start....2020-10-12 08:18:28.489 UTC [46] LOG:  starting PostgreSQL 12.4 (Debian 12.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1       | 2020-10-12 08:18:28.499 UTC [46] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1       | 2020-10-12 08:18:28.545 UTC [47] LOG:  database system was shut down at 2020-10-12 08:18:25 UTC
db_1       | 2020-10-12 08:18:28.557 UTC [46] LOG:  database system is ready to accept connections
db_1       |  done
db_1       | server started
db_1       | 
db_1       | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1       | 
db_1       | waiting for server to shut down...2020-10-12 08:18:28.572 UTC [46] LOG:  received fast shutdown request
db_1       | .2020-10-12 08:18:28.581 UTC [46] LOG:  aborting any active transactions
db_1       | 2020-10-12 08:18:28.582 UTC [46] LOG:  background worker "logical replication launcher" (PID 53) exited with exit code 1
db_1       | 2020-10-12 08:18:28.583 UTC [48] LOG:  shutting down
db_1       | 2020-10-12 08:18:28.648 UTC [46] LOG:  database system is shut down
db_1       |  done
db_1       | server stopped
db_1       | 
db_1       | PostgreSQL init process complete; ready for start up.
db_1       | 
db_1       | 2020-10-12 08:18:28.693 UTC [1] LOG:  starting PostgreSQL 12.4 (Debian 12.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1       | 2020-10-12 08:18:28.694 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1       | 2020-10-12 08:18:28.694 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1       | 2020-10-12 08:18:28.712 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1       | 2020-10-12 08:18:28.751 UTC [55] LOG:  database system was shut down at 2020-10-12 08:18:28 UTC
db_1       | 2020-10-12 08:18:28.764 UTC [1] LOG:  database system is ready to accept connections

以前有人遇到过这个问题吗?你有什么建议我可以试试吗?

编辑:管理员容器日志与其他计算机的日志完全相同。他们只是在尝试连接时抛出这个错误,而不是一条ok消息:

Is the server running on host "postgres" (10.10.10.2) and accepting TCP/IP connections on port 5432?

我猜您是从某个站点安装了docker的。对于RHEL8,尝试使用不需要守护程序的Podman和Buildah-OCI兼容的替代方案。本文对此进行了解释。这些是RHEL8中默认的容器工具。

在RHEL 8环境中检查管理员容器中的日志,您将能够从中发现问题。

命令将是docker logs adminer container name

最新更新