Search code examples
dockerdocker-composedb2

How to proper healthcheck a db2 container so my app container can go up safely?


Currently i am just waiting a somewhat safe time frame before up the app container inside this docker-compose file:

# this compose spins up a db2 database for development purposes
version: "3"
services:
  db2: # https://hub.docker.com/r/ibmcom/db2
    #    image: ibmcom/db2:11.5.8.0
    image: icr.io/db2_community/db2:11.5.8.0
    privileged: true
    expose:
      - 50000
    ports:
      - "50000:50000"
    environment:
      LICENSE: accept
      DBNAME: sample
      DB2INSTANCE: db2inst1
      DB2INST1_PASSWORD: change-me-please
    healthcheck:
      # TODO find a real health check for db2
      test: [ "CMD", "sleep", "300"]
      interval: 30s
      timeout: 301s
      retries: 3
  app:
    build:
      context: ../../
      dockerfile: ./src/infrastructure/Dockerfile
    expose:
      - 7070
    ports:
      - "7071:7070"
    environment:
      APP_PROFILE: compose
    depends_on:
      db2:
        condition: service_healthy
    restart: on-failure

Is there any db2-specific tool able to give me better healthchecks? Any guidance is welcome. For context, the entire project is here.


Solution

  • There is a db2gcf utility which must be run on the server locally either as root or db2 instance owner (db2inst1 in your case). That is:
    db2gcf -s
    It returns the corresponding return code to check if needed.