From a45f2aa09cf6b80275c75244a051bcfbeea1e4e7 Mon Sep 17 00:00:00 2001 From: fumoboy007 <2100868+fumoboy007@users.noreply.github.com> Date: Thu, 22 Aug 2024 23:48:49 -0400 Subject: [PATCH] Add `HEALTHCHECK` instruction to `Dockerfile`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `Dockerfile` currently does not have a `HEALTHCHECK` instruction. Users of the Docker image currently need to add it manually (e.g. via Docker Compose). Instead, the `Dockerfile` itself should include the instruction. To determine whether the service is healthy, one can use the [`pg_isready`](https://www.postgresql.org/docs/current/app-pg-isready.html) program, which is already part of the image. The program “checks the connection status of a PostgreSQL database server”. Most of the default `HEALTHCHECK` [options](https://docs.docker.com/reference/dockerfile/#healthcheck) seem reasonable: ``` --interval=30s --timeout=30s --start-interval=5s --retries=3 ``` I set `--start-period=1s` because the default of `0s` is too quick for this program. Users of the image can still override the `HEALTHCHECK` instruction if they want to customize the command or the options. --- 12/alpine3.19/Dockerfile | 2 ++ 12/alpine3.20/Dockerfile | 2 ++ 12/bookworm/Dockerfile | 2 ++ 12/bullseye/Dockerfile | 2 ++ 13/alpine3.19/Dockerfile | 2 ++ 13/alpine3.20/Dockerfile | 2 ++ 13/bookworm/Dockerfile | 2 ++ 13/bullseye/Dockerfile | 2 ++ 14/alpine3.19/Dockerfile | 2 ++ 14/alpine3.20/Dockerfile | 2 ++ 14/bookworm/Dockerfile | 2 ++ 14/bullseye/Dockerfile | 2 ++ 15/alpine3.19/Dockerfile | 2 ++ 15/alpine3.20/Dockerfile | 2 ++ 15/bookworm/Dockerfile | 2 ++ 15/bullseye/Dockerfile | 2 ++ 16/alpine3.19/Dockerfile | 2 ++ 16/alpine3.20/Dockerfile | 2 ++ 16/bookworm/Dockerfile | 2 ++ 16/bullseye/Dockerfile | 2 ++ 17/alpine3.19/Dockerfile | 2 ++ 17/alpine3.20/Dockerfile | 2 ++ 17/bookworm/Dockerfile | 2 ++ 17/bullseye/Dockerfile | 2 ++ Dockerfile-alpine.template | 2 ++ Dockerfile-debian.template | 2 ++ 26 files changed, 52 insertions(+) diff --git a/12/alpine3.19/Dockerfile b/12/alpine3.19/Dockerfile index e3f5683277..0c6bc92135 100644 --- a/12/alpine3.19/Dockerfile +++ b/12/alpine3.19/Dockerfile @@ -232,3 +232,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/12/alpine3.20/Dockerfile b/12/alpine3.20/Dockerfile index 2c1db6c7f0..3109946c92 100644 --- a/12/alpine3.20/Dockerfile +++ b/12/alpine3.20/Dockerfile @@ -232,3 +232,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/12/bookworm/Dockerfile b/12/bookworm/Dockerfile index d80c0a4345..44b9629fcf 100644 --- a/12/bookworm/Dockerfile +++ b/12/bookworm/Dockerfile @@ -223,3 +223,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/12/bullseye/Dockerfile b/12/bullseye/Dockerfile index f11f9db297..2c170b3f81 100644 --- a/12/bullseye/Dockerfile +++ b/12/bullseye/Dockerfile @@ -223,3 +223,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/13/alpine3.19/Dockerfile b/13/alpine3.19/Dockerfile index eb4350a655..7fe50c888f 100644 --- a/13/alpine3.19/Dockerfile +++ b/13/alpine3.19/Dockerfile @@ -232,3 +232,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/13/alpine3.20/Dockerfile b/13/alpine3.20/Dockerfile index d365154e29..b3c9c6736e 100644 --- a/13/alpine3.20/Dockerfile +++ b/13/alpine3.20/Dockerfile @@ -232,3 +232,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/13/bookworm/Dockerfile b/13/bookworm/Dockerfile index 8c9451e1b9..8388c6d69b 100644 --- a/13/bookworm/Dockerfile +++ b/13/bookworm/Dockerfile @@ -225,3 +225,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/13/bullseye/Dockerfile b/13/bullseye/Dockerfile index c8770da222..88c2ecc8cc 100644 --- a/13/bullseye/Dockerfile +++ b/13/bullseye/Dockerfile @@ -225,3 +225,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/14/alpine3.19/Dockerfile b/14/alpine3.19/Dockerfile index 533e23e6be..d89a8523bc 100644 --- a/14/alpine3.19/Dockerfile +++ b/14/alpine3.19/Dockerfile @@ -235,3 +235,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/14/alpine3.20/Dockerfile b/14/alpine3.20/Dockerfile index 4b89e0d558..873188c480 100644 --- a/14/alpine3.20/Dockerfile +++ b/14/alpine3.20/Dockerfile @@ -235,3 +235,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/14/bookworm/Dockerfile b/14/bookworm/Dockerfile index 88743d5041..ab27f473c6 100644 --- a/14/bookworm/Dockerfile +++ b/14/bookworm/Dockerfile @@ -223,3 +223,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/14/bullseye/Dockerfile b/14/bullseye/Dockerfile index a69d4098f9..1b0a44ec31 100644 --- a/14/bullseye/Dockerfile +++ b/14/bullseye/Dockerfile @@ -223,3 +223,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/15/alpine3.19/Dockerfile b/15/alpine3.19/Dockerfile index e9c2dbb37d..5f440554cf 100644 --- a/15/alpine3.19/Dockerfile +++ b/15/alpine3.19/Dockerfile @@ -238,3 +238,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/15/alpine3.20/Dockerfile b/15/alpine3.20/Dockerfile index 83e8a4640d..cdd6135117 100644 --- a/15/alpine3.20/Dockerfile +++ b/15/alpine3.20/Dockerfile @@ -238,3 +238,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/15/bookworm/Dockerfile b/15/bookworm/Dockerfile index 859acbfbdd..aebff076ad 100644 --- a/15/bookworm/Dockerfile +++ b/15/bookworm/Dockerfile @@ -223,3 +223,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/15/bullseye/Dockerfile b/15/bullseye/Dockerfile index aff946fa54..33750a32e2 100644 --- a/15/bullseye/Dockerfile +++ b/15/bullseye/Dockerfile @@ -223,3 +223,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/16/alpine3.19/Dockerfile b/16/alpine3.19/Dockerfile index 16f3df5884..9ffc264300 100644 --- a/16/alpine3.19/Dockerfile +++ b/16/alpine3.19/Dockerfile @@ -237,3 +237,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/16/alpine3.20/Dockerfile b/16/alpine3.20/Dockerfile index 33d01092b9..1800ec669d 100644 --- a/16/alpine3.20/Dockerfile +++ b/16/alpine3.20/Dockerfile @@ -237,3 +237,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/16/bookworm/Dockerfile b/16/bookworm/Dockerfile index c18ea696cd..cf2fd5a8f8 100644 --- a/16/bookworm/Dockerfile +++ b/16/bookworm/Dockerfile @@ -223,3 +223,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/16/bullseye/Dockerfile b/16/bullseye/Dockerfile index 012558e80c..065b011cb7 100644 --- a/16/bullseye/Dockerfile +++ b/16/bullseye/Dockerfile @@ -223,3 +223,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/17/alpine3.19/Dockerfile b/17/alpine3.19/Dockerfile index b969aee611..cf045d2e4a 100644 --- a/17/alpine3.19/Dockerfile +++ b/17/alpine3.19/Dockerfile @@ -235,3 +235,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/17/alpine3.20/Dockerfile b/17/alpine3.20/Dockerfile index c8c66543d7..7cbdda8efc 100644 --- a/17/alpine3.20/Dockerfile +++ b/17/alpine3.20/Dockerfile @@ -235,3 +235,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/17/bookworm/Dockerfile b/17/bookworm/Dockerfile index 4f6df7d667..c25f669744 100644 --- a/17/bookworm/Dockerfile +++ b/17/bookworm/Dockerfile @@ -223,3 +223,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/17/bullseye/Dockerfile b/17/bullseye/Dockerfile index 8da5fa76ca..286bef51bf 100644 --- a/17/bullseye/Dockerfile +++ b/17/bullseye/Dockerfile @@ -223,3 +223,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/Dockerfile-alpine.template b/Dockerfile-alpine.template index 3d6236e6e8..966795f5a2 100644 --- a/Dockerfile-alpine.template +++ b/Dockerfile-alpine.template @@ -250,3 +250,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1 diff --git a/Dockerfile-debian.template b/Dockerfile-debian.template index 1fa84903ac..3894287360 100644 --- a/Dockerfile-debian.template +++ b/Dockerfile-debian.template @@ -221,3 +221,5 @@ STOPSIGNAL SIGINT EXPOSE 5432 CMD ["postgres"] + +HEALTHCHECK --start-period=1s CMD pg_isready || exit 1