GithubHelp home page GithubHelp logo

ericf / health_check_nginx_docker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from equivalent/health_check_nginx_docker

2.0 1.0 0.0 4 KB

simple Docker image running Nginx that responds to /health-check with 200

License: MIT License

health_check_nginx_docker's Introduction

Health Check Nginx Docker image

Just simple docker image running NginX responding to:

/                  # 404 Not Found
/health-check      # 200 OK
/health-check.html # 200 OK
/healthcheck       # 200 OK
/healthcheck.html  # 200 OK

Usage example

This is docker image is useful if you are configuring server that is running a worker server running background tasks independent of the Web-Server.

That means that the BG server does not necessary need to respond to http requests yet you still want to expose http health-check endpoint that can be pinged.

docker pull equivalent/health_check_nginx:1.0
# ..or
docker pull equivalent/health_check_nginx:latest

docker run -p 80:80 -d equivalent/health_check_nginx

curl -v localhost/                  # 404 Not Found
curl -v localhost/health-check      # 200 OK
curl -v localhost/health-check.html # 200 OK
curl -v localhost/healthcheck       # 200 OK
curl -v localhost/healthcheck.html  # 200 OK

AWS Elastic Beanstalk example

If you have AWS ElasticBeanstalk enviroment (EB), you can configure "healthcheck endpoint" (e.g.: http://my-enviromnet-app.elasticbeanstalk.com/health-check.html).

When that healthcheck is not responding with Status 200 AWS EB will remove that instance from load balancer or it will raise "red" flang in server monitoring.

Now here is the useful part. When you are running Docker environment on AWS ElasticBeanstalk if any of your esential containers is failing (e.g. memory leak) EB will retriger EB job. That means it effectively restarts all docker containers in the definition. So this Nginx health-check container will restart as well.

Dockerrun.aws.json

{
  "AWSEBDockerrunVersion": 2,

  "containerDefinitions": [
    {
      "name": "background-worker",
      "image": "my-company/my-bg-worker-app",
      "essential": true
    },
    {
      "name": "health_check_nginx",
      "image": "equivalent/health_check_nginx",
      "essential": true,
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80
        }
      ]
    }
  ]
}

Other examples

Just make sure that when your "primary" docker image (e.g. BG worker) goes down it will bring down this docker container as well (e.g. specify in docker-compose.yml specify depends_on: my_bg_worker for this container.

Building docker on your local machine

git clone [email protected]:equivalent/health_check_nginx_docker.git
docker build -t=nginx-health .
docker run -p 80:80 -it nginx-health

health_check_nginx_docker's People

Contributors

equivalent 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.