Hello,

In DevOps practices, it’s standard procedure to verify that a service is running before other services that depend on it are started. This check ensures stability and reliability across interconnected services. For example, in Docker Compose in a service description a directive like depends_on can be used to wait until all healthchecks done before starting the service.

Docker Compose:

To make a simple health check for your service you can do something like this (taking into account that your application is running on 8080 port):

services:
  service-name:
    image: your-image
    healthcheck:
      test: ["CMD", "wget", "--spider", "-q", "http://localhost:8080/health"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 15s
    depends_on:
      some-other-service-name:
        condition: service_healthy

You may ask, why wget and not a curl? To make a curl request you may need to install it along with your app by adding something like RUN apk --no-cache add curl or use an image which already has a preinstalled curl:

  • The official Nginx image generally has curl preinstalled
  • The official Python images (not the slim versions) generally come with curl preinstalled.
  • The official Node.js Docker images (especially full versions, not -slim) usually come with curl preinstalled.
  • FROM ubuntu:latest

many minimal images, especially lightweight ones like Alpine and Debian Slim, do not include curl by default to keep the image size small.

Kubernetes:

    livenessProbe:
      httpGet:
          path: /health
          port: 8080
      initialDelaySeconds: 15
      periodSeconds: 10
      readinessProbe:
      httpGet:
          path: /health
          port: 8080
      initialDelaySeconds: 15
      periodSeconds: 10    
// Kubernetes will only send traffic to this pod after the readinessProbe passes.
    readinessProbe: 
      httpGet:
        path: /health
        port: 8080
      initialDelaySeconds: 5
      periodSeconds: 10

By the way the status by default is tracked by such monitoring tools as NetData

Checkout my tweet about it