我已经为PostgreSQL和pgAdmin4创建了yml文件。想对这两个容器进行健康检查。我应该怎么做?
我已经为PostgreSQL和pgAdmin4创建了yml文件。想对这两个容器进行健康检查。我应该怎么做?
对于PostgreSQL,您需要从容器中运行pg_isready -U用户名
,其中用户名
是DB的有效用户名。
对于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秒,否则将面临以下错误/警告:
工作进程pid[<>]已经由于信号9而终止