I am trying to add a health check for my docker as suggested here. My docker compose looks like below
version: '3'
services:
# IMPORTANT NOTE: All other services will share the network on pgadmin service (network_mode: "service:pgadmin"), so ports need to be opened here instead of other the services.
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
ports:
- "6555:80" # pg admin
- "6432:6432" # postgres-db
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: admin
postgres-db:
container_name: test-db
image: postgres:14.4
network_mode: "service:pgadmin"
command: -p 6432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 5s
timeout: 5s
retries: 3
But the Postgres container is being reported as unhealthy.
debrajmanna@debrajmanna-DX6QR261G3 java % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fec13f7d67e3 postgres:14.4 "docker-entrypoint.s…" 17 seconds ago Up 16 seconds (unhealthy) test-db
b4042b8e906b dpage/pgadmin4 "/entrypoint.sh" 17 seconds ago Up 16 seconds 443/tcp, 0.0.0.0:6432->6432/tcp, 0.0.0.0:6555->80/tcp pgadmin
Can someone suggest what I am doing wrong?
2
Answers
I need to add
-p 6432
in the health check. The working docker-compose file.The reason for adding
PGUSER
is explained here.try this for postgres-db:
command: postgres -p 6432
It seems to me here is a mistake.