我有一个 Kong API Gateway容器和一个 postgres容器,我需要在运行迁移之前检查 postgres 是否已经启动并从 Kong 容器准备就绪。我正在考虑在我的 Dockerfile 中使用 RUN yum install postgresql -y && yum clean all
并使用 psql
将 postgres 客户端实用程序安装到基于官方 Kong 图像的自定义图像中> 或 pg_isready
来实现这一点。我创建了一个名为 polling
的 postgres 用户,密码为空,专门用于通过这两个实用程序检查服务器的状态。它们都不起作用。
我尝试从自定义 Kong 图像执行这些命令:
psql。命令
psql -h postgres -U polling -w -c '\l'
失败并出现错误psql: fe_sendauth: no password supplied
。但是用户没有密码。我究竟做错了什么?描述了使用 psql 检查服务器是否准备就绪的完整 shell 脚本 here .pg_isready。我不知道如何将此实用程序单独安装到基于官方 Kong 图像的自定义图像中,而该图像又基于
centos:7
图像,postgresql
包没有'不包括pg_isready
。仅安装了这些实用程序,并且可以在/usr/bin
中找到它们:pg_config
、pg_dump
、pg_dumpall
、pg_restore
,psql
。如何安装pg_isready
?我不想在 Kong 镜像中安装完整的服务器。
最佳答案
这是一个使用 PostgreSQL 提供的 pg_isready
工具的 shell one liner。
调用外部docker:
DOCKER_CONTAINER_NAME="mypgcontainer"
timeout 90s bash -c "until docker exec $DOCKER_CONTAINER_NAME pg_isready ; do sleep 5 ; done"
关于postgresql - Docker - 检查 postgres 是否准备就绪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46516584/