skip to Main Content

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


  1. Chosen as BEST ANSWER

    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: [email protected]
          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.


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

    It seems to me here is a mistake.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search