An open API service indexing awesome lists of open source software.

https://github.com/sdavids/sdavids-docker-healthcheck

Docker health checks
https://github.com/sdavids/sdavids-docker-healthcheck

docker golang nodejs rust

Last synced: 4 months ago
JSON representation

Docker health checks

Awesome Lists containing this project

README

          

// SPDX-FileCopyrightText: © 2024 Sebastian Davids
// SPDX-License-Identifier: Apache-2.0
= sdavids-docker-healthcheck
Sebastian Davids
// Metadata:
:description: Docker health checks
// Settings:
:sectnums:
:sectanchors:
:sectlinks:
:toc: macro
:toclevels: 3
:toc-placement!:
:hide-uri-scheme:
:source-highlighter: rouge
:rouge-style: github
// Refs:
:docker-install-url: https://docs.docker.com/install/
:go-install-url: https://go.dev/doc/install
:golangci-install-url: https://golangci-lint.run/usage/install/#local-installation
:easyrsa-install-url: https://easy-rsa.readthedocs.io/en/latest/#obtaining-and-using-easy-rsa
:fnm-install-url: https://github.com/Schniz/fnm#installation
:hadolint-install-url: https://github.com/hadolint/hadolint?tab=readme-ov-file#install
:nvm-install-url: https://github.com/nvm-sh/nvm#installing-and-updating
:rust-install-url: https://www.rust-lang.org/learn/get-started

ifdef::env-browser[:outfilesuffix: .adoc]

ifdef::env-github[]
:outfilesuffix: .adoc
:important-caption: :heavy_exclamation_mark:
:note-caption: :information_source:
:warning-caption: :warning:
endif::[]

toc::[]

Available Docker health checks:

link:go/http/README.adoc[Go http]:: a Go-based Docker health check for an HTTP URL
link:go/https/README.adoc[Go https]:: a Go-based Docker health check for an HTTP(S) URL
link:java/http/README.adoc/[Java http]:: a Java-based Docker health check for an HTTP URL
link:js/nodejs/README.adoc/[JavaScript Node.js]:: a Node.js-based Docker health check for an HTTP(S) URL
link:rust/http/README.adoc[Rust http]:: a Rust-based Docker health check for an HTTP URL
link:rust/https/README.adoc[Rust https]:: a Rust-based Docker health check for an HTTP(S) URL
link:shell/nc/README.adoc[shell nc]:: a nc-based Docker health check for a daemon port

== Size Comparison

[options="header,autowidth"]
|===
|Program |Size |Notes

|<>
>|4.0K
|only check the daemon's port

|<>
>|4.0K
|the `node` binary would add 42.1M

|<>
>|208.0K
|

|<>
>|548.0K
|

|<>
>|3.6M
|

|<>
>|5.9M
|

|<>
>|5.9M
|

|<>
>|9.5M
|

|<>
>|11.0M
|

|<>
>|10.7M
|

|<>
>|22.0M
|
|===

=== Go

[#go-http]
==== http

[,console]
----
$ cd go/http
$ scripts/docker_build.sh -p linux/amd64 -t go-http
$ docker run --platform=linux/amd64 --rm de.sdavids/sdavids-docker-healthcheck:go-http sh -c 'du -kh /usr/local/bin/healthcheck'
5.9M /usr/local/bin/healthcheck
----

===== Usage

link:go/http/README.adoc#usage[Go http]

[#go-https]
==== https

[,console]
----
$ cd go/https
$ scripts/docker_build.sh -p linux/amd64 -t go-https
$ docker run --platform=linux/amd64 --rm de.sdavids/sdavids-docker-healthcheck:go-https sh -c 'du -kh /usr/local/bin/healthcheck'
5.9M /usr/local/bin/healthcheck
----

===== Usage

link:go/https/README.adoc#usage[Go https]

=== Java

[#java-http]
==== http

[NOTE]
====
You need to link:java/http/README.adoc#docker-login[authenticate] with the _ghcr.io Container registry_ to build the image.
====

[,console]
----
$ cd java/http
$ scripts/docker_build.sh -p linux/amd64 -t java-http
$ docker run --platform=linux/amd64 --rm de.sdavids/sdavids-docker-healthcheck:java-http sh -c 'du -kh /usr/local/bin/healthcheck'
3.6M /usr/local/bin/healthcheck
----

===== Usage

link:java/http/README.adoc#usage[Java http]

=== JavaScript

[#js-nodejs]
==== Node.js

[NOTE]
====
This health check is only useful in a Node.js Docker image, i.e., an image where the `node` binary already exists--the `node` binary would add 42.1M.
====

[,console]
----
$ cd js/nodejs
$ scripts/docker_build.sh -p linux/amd64 -t js-nodejs
$ docker run --platform=linux/amd64 --rm de.sdavids/sdavids-docker-healthcheck:js-nodejs sh -c 'du -kh /node/healthcheck.mjs'
4.0K /node/healthcheck.mjs
$ docker run --platform=linux/amd64 --rm de.sdavids/sdavids-docker-healthcheck:js-nodejs sh -c 'du -kh /usr/bin/node'
42.1M /usr/bin/node
----

===== Usage

link:js/nodejs/README.adoc#usage[js - nodejs]

=== Rust

[#rust-http]
==== http

[,console]
----
$ cd rust/http
$ scripts/docker_build.sh -p linux/amd64 -t rust-http
$ docker run --platform=linux/amd64 --rm de.sdavids/sdavids-docker-healthcheck:rust-http sh -c 'du -kh /usr/local/bin/healthcheck'
208.0K /usr/local/bin/healthcheck
----

===== Usage

link:rust/http/README.adoc#usage[Rust http]

[#rust-https]
==== https

[NOTE]
====

You need to create a certificate authority and its root certificate:

[,console]
----
$ cd rust/https
$ scripts/create_ca.sh
$ scripts/copy_ca_root_cert.sh
----

Or copy an existing root certificate:

[,console]
----
$ cd rust/https
$ scripts/copy_ca_root_cert.sh
----
====

[,console]
----
$ cd rust/https
$ scripts/docker_build.sh -p linux/amd64 -t rust-https
$ docker run --platform=linux/amd64 --rm de.sdavids/sdavids-docker-healthcheck:rust-https sh -c 'du -kh /usr/local/bin/healthcheck'
548.0K /usr/local/bin/healthcheck
----

===== Usage

link:rust/https/README.adoc#usage[Rust https]

=== shell

[#shell-nc]
==== nc

[NOTE]
====
This health check will only check if the daemon's port is reachable, i.e., it will not check the HTTP body or status code of the response.
====

[,console]
----
$ cd shell/nc
$ scripts/docker_build.sh -p linux/amd64 -t shell-nc
$ docker run --platform=linux/amd64 --rm de.sdavids/sdavids-docker-healthcheck:shell-nc sh -c 'du -kh /usr/local/bin/healthcheck'
4.0K /usr/local/bin/healthcheck
----

===== Usage

link:shell/nc/README.adoc#usage[shell nc]

=== curl

[#curl-alpine]
==== alpine

[,console]
----
$ docker run --platform=linux/amd64 --rm alpine:3.23.3 sh -c "apk --no-cache --quiet --no-progress add curl=8.17.0-r1 && ldd /usr/bin/curl | awk '{ print $ 3}' | xargs du -ckshL /usr/bin/curl"
256.0K /usr/bin/curl
724.0K /usr/lib/libcurl.so.4
104.0K /usr/lib/libz.so.1
652.0K /lib/ld-musl-x86_64.so.1
236.0K /usr/lib/libcares.so.2
144.0K /usr/lib/libnghttp3.so.9
132.0K /usr/lib/libnghttp2.so.14
196.0K /usr/lib/libidn2.so.0
76.0K /usr/lib/libpsl.so.5
820.0K /usr/lib/libssl.so.3
4.8M /usr/lib/libcrypto.so.3
696.0K /usr/lib/libzstd.so.1
56.0K /usr/lib/libbrotlidec.so.1
1.8M /usr/lib/libunistring.so.5
140.0K /usr/lib/libbrotlicommon.so.1
10.7M total
----

[#curl-debian]
==== debian

[,console]
----
$ docker run --platform=linux/amd64 --rm debian:13.3-slim sh -c "apt-get -qq update && apt-get -qq install -y curl=8.14.1-2+deb13u2 >/dev/null 2>&1 && ldd /usr/bin/curl | awk '{ print $ 3}' | xargs du -ckshL /usr/bin/curl"
316K /usr/bin/curl
964K /lib/x86_64-linux-gnu/libcurl.so.4
124K /lib/x86_64-linux-gnu/libz.so.1
2.0M /lib/x86_64-linux-gnu/libc.so.6
172K /lib/x86_64-linux-gnu/libnghttp3.so.9
196K /lib/x86_64-linux-gnu/libnghttp2.so.14
200K /lib/x86_64-linux-gnu/libidn2.so.0
120K /lib/x86_64-linux-gnu/librtmp.so.1
288K /lib/x86_64-linux-gnu/libssh2.so.1
76K /lib/x86_64-linux-gnu/libpsl.so.5
1.1M /lib/x86_64-linux-gnu/libssl.so.3
6.3M /lib/x86_64-linux-gnu/libcrypto.so.3
340K /lib/x86_64-linux-gnu/libgssapi_krb5.so.2
392K /lib/x86_64-linux-gnu/libldap.so.2
64K /lib/x86_64-linux-gnu/liblber.so.2
808K /lib/x86_64-linux-gnu/libzstd.so.1
52K /lib/x86_64-linux-gnu/libbrotlidec.so.1
2.0M /lib/x86_64-linux-gnu/libunistring.so.5
2.2M /lib/x86_64-linux-gnu/libgnutls.so.30
300K /lib/x86_64-linux-gnu/libhogweed.so.6
340K /lib/x86_64-linux-gnu/libnettle.so.8
556K /lib/x86_64-linux-gnu/libgmp.so.10
864K /lib/x86_64-linux-gnu/libkrb5.so.3
184K /lib/x86_64-linux-gnu/libk5crypto.so.3
20K /lib/x86_64-linux-gnu/libcom_err.so.2
52K /lib/x86_64-linux-gnu/libkrb5support.so.0
108K /lib/x86_64-linux-gnu/libsasl2.so.2
140K /lib/x86_64-linux-gnu/libbrotlicommon.so.1
1.7M /lib/x86_64-linux-gnu/libp11-kit.so.0
88K /lib/x86_64-linux-gnu/libtasn1.so.6
24K /lib/x86_64-linux-gnu/libkeyutils.so.1
64K /lib/x86_64-linux-gnu/libresolv.so.2
48K /lib/x86_64-linux-gnu/libffi.so.8
22M total
----

=== wget

[#wget-alpine]
==== alpine

[,console]
----
$ docker run --platform=linux/amd64 --rm alpine:3.23.3 sh -c "apk --no-cache --quiet --no-progress add wget=1.25.0-r2 && ldd /usr/bin/wget | awk '{ print $ 3}' | xargs du -ckshL /usr/bin/wget"
404.0K /usr/bin/wget
764.0K /usr/lib/libpcre2-8.so.0
196.0K /usr/lib/libidn2.so.0
820.0K /usr/lib/libssl.so.3
4.8M /usr/lib/libcrypto.so.3
104.0K /usr/lib/libz.so.1
652.0K /lib/ld-musl-x86_64.so.1
1.8M /usr/lib/libunistring.so.5
9.5M total
----

[#wget-debian]
==== debian

[,console]
----
$ docker run --platform=linux/amd64 --rm debian:13.3-slim sh -c "apt-get -qq update && apt-get -qq install -y wget=1.25.0-2 >/dev/null 2>&1 && ldd /usr/bin/wget | awk '{ print $ 3}' | xargs du -ckshL /usr/bin/wget"
472K /usr/bin/wget
696K /lib/x86_64-linux-gnu/libpcre2-8.so.0
40K /lib/x86_64-linux-gnu/libuuid.so.1
200K /lib/x86_64-linux-gnu/libidn2.so.0
340K /lib/x86_64-linux-gnu/libnettle.so.8
2.2M /lib/x86_64-linux-gnu/libgnutls.so.30
124K /lib/x86_64-linux-gnu/libz.so.1
76K /lib/x86_64-linux-gnu/libpsl.so.5
2.0M /lib/x86_64-linux-gnu/libc.so.6
2.0M /lib/x86_64-linux-gnu/libunistring.so.5
1.7M /lib/x86_64-linux-gnu/libp11-kit.so.0
88K /lib/x86_64-linux-gnu/libtasn1.so.6
300K /lib/x86_64-linux-gnu/libhogweed.so.6
556K /lib/x86_64-linux-gnu/libgmp.so.10
48K /lib/x86_64-linux-gnu/libffi.so.8
11M total
----

== Development

=== Format Source Code

[,console]
----
$ scripts/format.sh
----

=== Lint Source Code

[,console]
----
$ scripts/lint.sh
----

== Development Environment Setup

[IMPORTANT]
====
After cloning this repository, you need to install the Git hooks and configure the https://git-scm.com/docs/git-config#Documentation/git-config.txt-blameignoreRevsFile[ignore-revs-file]:

[,console]
----
$ git config set core.hooksPath .githooks
$ git config set blame.ignoreRevsFile .git-blame-ignore-revs
----
====

=== Installation

==== Docker

Install {docker-install-url}[Docker].

==== easyrsa

[IMPORTANT]
====
Ensure that you install version `3.1.7` and not `3.2.x`!
====

===== Linux

Install {easyrsa-install-url}[easyrsa].

===== Mac

[WARNING]
====
Unfortunately, homebrew provides `easy-rsa` version `3.2.x` .
====

[,console]
----
$ curl -L https://github.com/OpenVPN/easy-rsa/releases/download/v3.1.7/EasyRSA-3.1.7.tgz -o ~/Downloads/easy-rsa.tgz
$ tar -xzf ~/Downloads/easy-rsa.tgz -C ~/.local/share
$ mv ~/.local/share/EasyRSA-3.1.7 ~/.local/share/easyrsa
$ ln -s ~/.local/share/easyrsa/easyrsa ~/.local/bin/easyrsa
$ rm ~/Downloads/easy-rsa.tgz
----

==== Go

Install {go-install-url}[Go].

==== golangci-lint

Install {golangci-install-url}[golangci-lint].

==== hadolint

===== Linux

Install {hadolint-install-url}[hadolint].

===== Mac

[,console]
----
$ brew install hadolint
----

[#jdk]
==== JDK

There are https://whichjdk.com[several different JDKs] and multiple options for installing them.

The https://whichjdk.com/#what-is-the-best-way-to-install-a-jdk-for-local-development[recommended] way is to https://sdkman.io/install[install via SDKMAN!]:

[,console]
----
$ sdk install java
----

===== More Information

https://sdkman.io/jdks[SDKMAN JDKs]

==== Node Version Manager

Install {fnm-install-url}[fnm] or {nvm-install-url}[NVM].

===== fnm

.~/.zprofile
[,zsh]
----
if command -v fnm > /dev/null 2>&1; then
eval "$(fnm env --use-on-cd)"
fi
----

===== nvm

.~/.zshrc
[,zsh]
----
export NVM_DIR="${HOME}/.nvm"

[ -s "${NVM_DIR}/nvm.sh" ] && . "${NVM_DIR}/nvm.sh"
[ -s "${NVM_DIR}/bash_completion" ] && . "${NVM_DIR}/bash_completion"

if command -v nvm > /dev/null 2>&1; then
autoload -U add-zsh-hook
load-nvmrc() {
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "${nvmrc_path}" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "${nvmrc_node_version}" = "N/A" ]; then
nvm install
elif [ "${nvmrc_node_version}" != "$(nvm version)" ]; then
nvm use
fi
elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}

add-zsh-hook chpwd load-nvmrc
load-nvmrc
fi
----

==== Rust

Install {rust-install-url}[Rust].

[,console]
----
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --component rust-analyzer
----

==== shellcheck

===== Linux

[,console]
----
$ sudo apt-get install shellcheck
----

===== Mac

[,console]
----
$ brew install shellcheck
----

==== shfmt

===== Linux

[,console]
----
$ sudo apt-get install shfmt
----

===== Mac

[,console]
----
$ brew install shfmt
----

==== yamllint

===== Linux

[,console]
----
$ sudo apt-get install yamllint
----

===== Mac

[,console]
----
$ brew install yamllint
----