1

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: pgadmin4@pgadmin.org
      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?

tuk
  • 5,941
  • 14
  • 79
  • 162

2 Answers2

1

I need to add -p 6432 in the health check. The working docker-compose file.

version: '3'
services:
  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4
    ports:
      - "6555:80"       # pg admin
      - "6432:6432"     # postgres-db
    environment:
      PGADMIN_DEFAULT_EMAIL: pgadmin4@pgadmin.org
      PGADMIN_DEFAULT_PASSWORD: admin

  postgres-db:
    # Postgres version should be compatible with Aurora:
    # https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Updates.20180305.html
    container_name: test-db
    image: postgres:14.4
    network_mode: "service:pgadmin"
    command: -p 6432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      PGUSER: postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -p 6432"]
      interval: 5s
      timeout: 5s
      retries: 3

The reason for adding PGUSER is explained here.

tuk
  • 5,941
  • 14
  • 79
  • 162
-2

try this for postgres-db: command: postgres -p 6432

It seems to me here is a mistake.

nsx.snx
  • 1
  • 2
  • No does not work. – tuk Mar 15 '23 at 17:02
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 22 '23 at 00:45