Jump to content

Linux/Docker/Healthcheck: Difference between revisions

From Wiki
Marcluer (talk | contribs)
mNo edit summary
Marcluer (talk | contribs)
mNo edit summary
 
Line 7: Line 7:
     healthcheck:
     healthcheck:
       test:            ["CMD", "curl", "-f", "http://localhost"]
       test:            ["CMD", "curl", "-f", "http://localhost"]
      test:            ["CMD-SHELL", "curl -f http://localhost || exit 1"]
                      ["CMD-SHELL", "curl -f http://localhost || exit 1"]
                      ["CMD", "wget", "-qO-", "http://localhost:4195/ready"]
                      wget --no-verbose --tries=1 --spider http://localhost || exit 1
       interval:        (default: 30s)
       interval:        (default: 30s)
       timeout:        (default: 30s)   
       timeout:        (default: 30s)   
       retries:        (default: 3)    # number of consecutive failures before unhealthy
       retries:        (default: 3)    # number of consecutive failures before unhealthy
       start_period:    (default 0s)   # grace period after start, failures will not count towards consecutive failures
       start_period:    (default: 0s)   # grace period after start, failures will not count towards consecutive failures
       start_interval:  (default: 5s)  # time between checks, during start-period
       start_interval:  (default: 5s)  # time between checks, during start-period



Latest revision as of 10:53, 19 June 2025

docker-compose.yml

service:
  web:
    image: ...  
    ...
    healthcheck:
      test:            ["CMD", "curl", "-f", "http://localhost"]
                       ["CMD-SHELL", "curl -f http://localhost || exit 1"]
                       ["CMD", "wget", "-qO-", "http://localhost:4195/ready"]
                       wget --no-verbose --tries=1 --spider http://localhost || exit 1
      interval:        (default: 30s)
      timeout:         (default: 30s)  
      retries:         (default: 3)    # number of consecutive failures before unhealthy
      start_period:    (default: 0s)   # grace period after start, failures will not count towards consecutive failures
      start_interval:  (default: 5s)   # time between checks, during start-period

    depends_on:
      database:
        condition:     (service_started, service_healthy)
        restart: true

Exit codes

  • 0: success
  • 1: failure / unhealthy