From 47c0ddbc33a38cf36b4eb65c4814f2d382e8f237 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Mon, 13 Jun 2016 14:39:08 -0700 Subject: [PATCH] Add "postgres" --- postgres/Dockerfile | 5 +++++ postgres/docker-healthcheck | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 postgres/Dockerfile create mode 100755 postgres/docker-healthcheck diff --git a/postgres/Dockerfile b/postgres/Dockerfile new file mode 100644 index 0000000..eb77747 --- /dev/null +++ b/postgres/Dockerfile @@ -0,0 +1,5 @@ +FROM postgres + +COPY docker-healthcheck /usr/local/bin/ + +HEALTHCHECK CMD ["docker-healthcheck"] diff --git a/postgres/docker-healthcheck b/postgres/docker-healthcheck new file mode 100755 index 0000000..06a11b0 --- /dev/null +++ b/postgres/docker-healthcheck @@ -0,0 +1,21 @@ +#!/bin/bash +set -eo pipefail + +user="${POSTGRES_USER:-postgres}" + +export PGPASSWORD="${POSTGRES_PASSWORD:-}" + +args=( + # force postgres to not use the local unix socket (test "external" connectibility) + --host "$(hostname --ip-address || echo '127.0.0.1')" + --username "$user" + --quiet --no-align --tuples-only +) + +if select="$(echo 'SELECT 1' | psql "${args[@]}")" && [ "$select" = '1' ]; then + exit 0 +fi + +# If the probe returns 2 ("starting") when the container has already moved out of the "starting" state then it is treated as "unhealthy" instead. +# https://github.com/docker/docker/blob/dcc65376bac8e73bb5930fce4cddc2350bb7baa2/docs/reference/builder.md#healthcheck +exit 2