Skip to content

Zeigren/healthchecks_docker

Repository files navigation

Docker Stack For Healthchecks

Docker Image Size (latest) Docker Pulls

Links

Tags

  • latest
  • v1.22.0
  • v1.21.0
  • v1.20.0

Stack

  • Python:Alpine - Healthchecks
  • Caddy or NGINX - web server

Usage

Use Docker Compose or Docker Swarm to deploy. Containers are available from both Docker Hub and the GitHub Container Registry.

There are examples for using either Caddy or NGINX as the web server and examples for using Caddy, NGINX, or Traefik for HTTPS (the Traefik example also includes using it as a reverse proxy). The NGINX examples are in the nginx folder.

Recommendations

I recommend using Caddy as the web server and either have it handle HTTPS or pair it with Traefik as they both have native ACME support for automatically getting HTTPS certificates from Let's Encrypt or will create self signed certificates for local use.

If you can I also recommend using Docker Swarm over Docker Compose as it supports Docker Secrets and Docker Configs.

If Caddy doesn't work for you or you are chasing performance then checkout the NGINX examples. I haven't done any performance testing but NGINX has a lot of configurability which may let you squeeze out better performance if you have a lot of users, also check the performance section below.

Configuration

Configuration consists of setting environment variables in the .yml files. More environment variables for configuring healthchecks can be found in docker-entrypoint.sh and for Caddy in healthchecks_caddyfile.

Setting the DOMAIN variable changes whether Caddy uses HTTP, HTTPS with a self signed certificate, or HTTPS with a certificate from Let's Encrypt or ZeroSSL. Check the Caddy documentation for more info.

On first run you'll need to create a superuser by attaching to the container and running python manage.py createsuperuser.

I personally use this with Traefik as a reverse proxy, I've included an example traefik.yml but it's not necessary.

You'll need to create the appropriate Docker Secrets and Docker Configs.

Any environment variables for Healthchecks in docker-entrypoint.sh can instead be set using Docker Secrets, there's an example of how to do this in the relevant .yml files.

Run with docker stack deploy --compose-file docker-swarm.yml healthchecks

Run with docker-compose -f docker-compose.yml up -d. View using 127.0.0.1:9080.

Performance Tuning

The web servers set the relevant HTTP headers to have browsers cache as much as they can for as long as they can while requiring browsers to check if those files have changed, this is to get the benefit of caching without having to deal with the caches potentially serving old content. If content doesn't change that often or can be invalidated in another way then this behavior can be changed to reduce the number of requests.

The number of workers Gunicorn uses can be set with the GUNICORN_WORKERS environment variable.

Theory of operation

The Dockerfile uses multi-stage builds, build hooks, and labels for automated builds on Docker Hub.

The multi-stage build creates a build container that has all the dependencies for the python packages which are installed into a python virtual environment. The production container copies the python virtual environment from the build container and runs healthchecks from there, this allows it to be much more lightweight.

On startup, the container first runs the docker-entrypoint.sh script before running gunicorn.

docker-entrypoint.sh creates configuration files and runs commands based on environment variables that are declared in the various .yml files.

env_secrets_expand.sh handles using Docker Secrets.

About

Alpine Based Docker Stack for Healthchecks with examples for use with Docker Compose, Docker Swarm, Caddy, NGINX, and Traefik.

Topics

Resources

License

Stars

Watchers

Forks