如何为pgadmin4执行docker-compose健康检查



我已经为postgresql和pgadmin4创建了yml文件。我想对这两个容器进行健康检查。我该怎么做呢?

对于PostgreSQL,您希望从容器pg_isready -U username运行,其中username是数据库的有效用户名。

对于pgAdmin,您希望从容器wget -O - http://localhost:80/misc/ping运行。

它看起来像这样:

services:
postgre:
image: postgres
environment:
- POSTGRES_USER=foo
healthcheck:
test: ["CMD", "pg_isready", "-U", "foo"]
...
pgadmin:
image: dpage/pgadmin4
healthcheck:
test: ["CMD", "wget", "-O", "-", "http://localhost:80/misc/ping"]
...

你可以在这里找到一个真实的例子

对于Postgres容器健康检查变量,使用如下:


healthcheck:
test: ["CMD-SHELL", "pg_isready --quiet --dbname=$${POSTGRES_DB}--username=$${POSTGRES_USER} || exit 1"]
interval: 10s
timeout: 10s
start_period: 30s
retries: 3

对于PgAdmin容器健康检查变量,使用如下命令:


healthcheck:
test: ["CMD", "ping localhost:80 || exit 1"]
interval: 10s
timeout: 10s
start_period: 160s
retries: 3

注意:对于pgAdmin容器,'start_period'变量应该至少为140秒,否则将面临以下错误/警告:

worker pid [<>]已终止信号9

最新更新