Git Product home page Git Product logo

docker-health-check's Introduction

We have two containers: server waits 30sec, then starts a node server that echos anything sent on port 8001. client starts up and sends "hello" to server.

What settings do we have for healthcheck?

  • retries - number of failed tests it takes to be considered unhealthy - default: 3
  • interval - how frequently tests are run - default: 30sec
  • timeout - if a test exceeds the timeout its considered a failed test - default: 30sec
  • start_period - initialization time, a failed test here doesn't count towards the retries. but a successful check does put the container into a "started state" - default: 0sec

A docker-compose up looks like this:

$ docker-compose up
Creating network "heath-check_default" with the default driver
Creating server ... done
Creating client ... done
Attaching to server, client
server    | Fri Sep 13 14:26:59 UTC 2019 Sleeping first
server    | Fri Sep 13 14:27:29 UTC 2019 Launching server
client    | Fri Sep 13 14:27:30 UTC 2019 Server says hello

You can inspect the last 5 health checks with docker inspect server. The first failed check happens @ 14:27:09. The client container launches and we can talk to server.

{
  "Status": "healthy",
  "FailingStreak": 0,
  "Log": [
    {
      "Start": "2019-09-13T14:27:09.3049552Z",
      "End": "2019-09-13T14:27:09.4649784Z",
      "ExitCode": 1,
      "Output": ""
    },
    {
      "Start": "2019-09-13T14:27:19.4691874Z",
      "End": "2019-09-13T14:27:19.6174443Z",
      "ExitCode": 1,
      "Output": ""
    },
    {
      "Start": "2019-09-13T14:27:29.6292309Z",
      "End": "2019-09-13T14:27:29.7892456Z",
      "ExitCode": 0,
      "Output": "hello\n"
    }
  ]
}

It's important to note was a failure looks like! If I change to interval: 5s we will get 3 failed health checks in the 30s seconds the server container sleeps.

docker-compose up exits with a failure. The server container does eventually become healthy, but the one unhealthy status causes docker-compose to never launch the client container.

$ docker-compose up
Creating network "heath-check_default" with the default driver
Creating server ... done

ERROR: for client  Container "4c8dffed0518" is unhealthy.
ERROR: Encountered errors while bringing up the project.

$ docker-compose ps
 Name         Command            State       Ports
--------------------------------------------------
server   /scripts/launch.sh   Up (healthy)

Note the "FailingStreak": 3 because the first failure occured within the start_period: 10s.

{
  "Status": "unhealthy",
  "FailingStreak": 3,
  "Log": [
    {
      "Start": "2019-09-13T14:37:35.8334418Z",
      "End": "2019-09-13T14:37:35.9811258Z",
      "ExitCode": 1,
      "Output": ""
    },
    {
      "Start": "2019-09-13T14:37:40.9858378Z",
      "End": "2019-09-13T14:37:41.1200684Z",
      "ExitCode": 1,
      "Output": ""
    },
    {
      "Start": "2019-09-13T14:37:46.1266745Z",
      "End": "2019-09-13T14:37:46.2563832Z",
      "ExitCode": 1,
      "Output": ""
    },
    {
      "Start": "2019-09-13T14:37:51.2618981Z",
      "End": "2019-09-13T14:37:51.484465Z",
      "ExitCode": 1,
      "Output": ""
    }
  ]
}

docker-health-check's People

Contributors

russau avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.