Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

kubernetes - Docker Compose health check of HTTP API using tools outside the container

I am implementing a Docker Compose health check for Prysm Docker container. Prysm is Ethereum 2 node.

My goal is to ensure that RPC APIs (gRPC, JSON-RPC) of Prysm are up before starting other services in the same Docker Compose file, as those services depend on Prysm. I can use depends_on of Docker Compose file for this, but I need to figure out how to construct a check that checks if Prysm HTTP ports are ready to accept traffic.

The equivalent Kubernetes health check is:

  readinessProbe:
    initialDelaySeconds: 180
    timeoutSeconds: 1
    periodSeconds: 60
    failureThreshold: 3
    successThreshold: 1
    httpGet:
      path: /healthz
      port: 9090
      scheme: HTTP
  livenessProbe:
    initialDelaySeconds: 60
    timeoutSeconds: 1
    periodSeconds: 60
    failureThreshold: 60
    successThreshold: 1
    httpGet:
      path: /healthz
      port: 9090
      scheme: HTTP

The problem with Prysm image is that it lacks normal UNIX tools within the image (curl, netcat, /bin/sh) one usually uses to create such checks.

Is there a way to implement an HTTP health check with Docker Compose that would use built-in features in compose (are there any) or commands from the host system instead of ones within the container?

question from:https://stackoverflow.com/questions/66046460/docker-compose-health-check-of-http-api-using-tools-outside-the-container

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I managed to accomplish this by creating another service using Dockerize image.

version: '3'
services:

  # Oracle connects to ETH1 and ETH2 nodes
  # oracle:
  stakewise:
    container_name: stakewise-oracle
    image: stakewiselabs/oracle:v1.0.1
    # Do not start oracle service until beacon health check succeeds
    depends_on:
      beacon_ready:
        condition: service_healthy

  # ETH2 Prysm node
  beacon:
    container_name: eth2-beacon
    image: gcr.io/prysmaticlabs/prysm/beacon-chain:latest
    restart: always
    hostname: beacon-chain

  # An external startup check tool for Prysm
  # Using https://github.com/jwilder/dockerize
  # Simply wait that TCP port of RPC becomes available before
  # starting the Oracle to avoid errors on the startup.
  beacon_ready:
    image: jwilder/dockerize
    container_name: eth2-beacon-ready
    command: "/bin/sh -c 'while true ; do dockerize -wait tcp://beacon-chain:3500 -timeout 300s ; sleep 99 ; done'"
    depends_on:
      - beacon
    healthcheck:
      test: ["CMD", "dockerize", "-wait", "tcp://beacon-chain:3500"]
      interval: 1s
      retries: 999

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...