From 48e60872b3f4f40c336a9f9eb23caec04cb849d0 Mon Sep 17 00:00:00 2001 From: szaimen Date: Fri, 18 Feb 2022 11:41:52 +0100 Subject: [PATCH] fix database import by waiting for the database to start Signed-off-by: szaimen --- Containers/postgresql/Dockerfile | 2 +- Containers/postgresql/start.sh | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Containers/postgresql/Dockerfile b/Containers/postgresql/Dockerfile index 3a560c90..1adc29a7 100644 --- a/Containers/postgresql/Dockerfile +++ b/Containers/postgresql/Dockerfile @@ -1,7 +1,7 @@ # From https://github.com/docker-library/postgres/blob/master/13/alpine/Dockerfile FROM postgres:13.5-alpine3.15 -RUN apk add --update --no-cache bash openssl shadow +RUN apk add --update --no-cache bash openssl shadow netcat-openbsd # We need to use the same gid and uid as on old installations RUN set -ex; \ diff --git a/Containers/postgresql/start.sh b/Containers/postgresql/start.sh index 28802762..153fa950 100644 --- a/Containers/postgresql/start.sh +++ b/Containers/postgresql/start.sh @@ -58,8 +58,11 @@ if ( [ -f "$DATADIR/PG_VERSION" ] && [ "$PG_MAJOR" != "$(cat "$DATADIR/PG_VERSIO # Create new database exec docker-entrypoint.sh postgres & - # Wait 10s for creation - sleep 10s + # Wait for creation + while ! nc -z localhost 11000; do + echo "Waiting for the database to start." + sleep 5 + done # Set correct permissions if grep -q "Owner: oc_admin" "$DUMP_FILE" && ! grep -q "Owner: oc_$POSTGRES_USER" "$DUMP_FILE"; then