1
0
mirror of https://github.com/docker-library/postgres.git synced 2025-07-28 10:42:06 +03:00

Merge pull request #72 from bakavic/fix-gce

Check that vol actually contains DB files, as opposed to a non-empty dir.
This commit is contained in:
Tianon Gravi
2015-07-20 11:09:28 -07:00
7 changed files with 105 additions and 91 deletions

View File

@ -2,17 +2,19 @@
set -e set -e
if [ "$1" = 'postgres' ]; then if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA" chown -R postgres "$PGDATA"
chmod g+s /run/postgresql chmod g+s /run/postgresql
chown -R postgres:postgres /run/postgresql chown -R postgres:postgres /run/postgresql
if [ -z "$(ls -A "$PGDATA")" ]; then # look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
gosu postgres initdb gosu postgres initdb
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
# check password first so we can ouptut the warning before postgres # check password first so we can output the warning before postgres
# messes it up # messes it up
if [ "$POSTGRES_PASSWORD" ]; then if [ "$POSTGRES_PASSWORD" ]; then
pass="PASSWORD '$POSTGRES_PASSWORD'" pass="PASSWORD '$POSTGRES_PASSWORD'"
@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
Docker's default configuration, this is Docker's default configuration, this is
effectively any other container on the same effectively any other container on the same
system. system.
Use "-e POSTGRES_PASSWORD=password" to set Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run". it in "docker run".
**************************************************** ****************************************************
EOWARN EOWARN
pass= pass=
authMethod=trust authMethod=trust
fi fi
: ${POSTGRES_USER:=postgres} : ${POSTGRES_USER:=postgres}
: ${POSTGRES_DB:=$POSTGRES_USER} : ${POSTGRES_DB:=$POSTGRES_USER}
@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
EOSQL EOSQL
echo echo
fi fi
if [ "$POSTGRES_USER" = 'postgres' ]; then if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER' op='ALTER'
else else
@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL EOSQL
echo echo
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
if [ -d /docker-entrypoint-initdb.d ]; then if [ -d /docker-entrypoint-initdb.d ]; then
for f in /docker-entrypoint-initdb.d/*.sh; do for f in /docker-entrypoint-initdb.d/*.sh; do
[ -f "$f" ] && . "$f" [ -f "$f" ] && . "$f"
done done
fi fi
fi fi
exec gosu postgres "$@" exec gosu postgres "$@"
fi fi

View File

@ -2,17 +2,19 @@
set -e set -e
if [ "$1" = 'postgres' ]; then if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA" chown -R postgres "$PGDATA"
chmod g+s /run/postgresql chmod g+s /run/postgresql
chown -R postgres:postgres /run/postgresql chown -R postgres:postgres /run/postgresql
if [ -z "$(ls -A "$PGDATA")" ]; then # look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
gosu postgres initdb gosu postgres initdb
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
# check password first so we can ouptut the warning before postgres # check password first so we can output the warning before postgres
# messes it up # messes it up
if [ "$POSTGRES_PASSWORD" ]; then if [ "$POSTGRES_PASSWORD" ]; then
pass="PASSWORD '$POSTGRES_PASSWORD'" pass="PASSWORD '$POSTGRES_PASSWORD'"
@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
Docker's default configuration, this is Docker's default configuration, this is
effectively any other container on the same effectively any other container on the same
system. system.
Use "-e POSTGRES_PASSWORD=password" to set Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run". it in "docker run".
**************************************************** ****************************************************
EOWARN EOWARN
pass= pass=
authMethod=trust authMethod=trust
fi fi
: ${POSTGRES_USER:=postgres} : ${POSTGRES_USER:=postgres}
: ${POSTGRES_DB:=$POSTGRES_USER} : ${POSTGRES_DB:=$POSTGRES_USER}
@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
EOSQL EOSQL
echo echo
fi fi
if [ "$POSTGRES_USER" = 'postgres' ]; then if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER' op='ALTER'
else else
@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL EOSQL
echo echo
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
if [ -d /docker-entrypoint-initdb.d ]; then if [ -d /docker-entrypoint-initdb.d ]; then
for f in /docker-entrypoint-initdb.d/*.sh; do for f in /docker-entrypoint-initdb.d/*.sh; do
[ -f "$f" ] && . "$f" [ -f "$f" ] && . "$f"
done done
fi fi
fi fi
exec gosu postgres "$@" exec gosu postgres "$@"
fi fi

View File

@ -2,17 +2,19 @@
set -e set -e
if [ "$1" = 'postgres' ]; then if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA" chown -R postgres "$PGDATA"
chmod g+s /run/postgresql chmod g+s /run/postgresql
chown -R postgres:postgres /run/postgresql chown -R postgres:postgres /run/postgresql
if [ -z "$(ls -A "$PGDATA")" ]; then # look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
gosu postgres initdb gosu postgres initdb
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
# check password first so we can ouptut the warning before postgres # check password first so we can output the warning before postgres
# messes it up # messes it up
if [ "$POSTGRES_PASSWORD" ]; then if [ "$POSTGRES_PASSWORD" ]; then
pass="PASSWORD '$POSTGRES_PASSWORD'" pass="PASSWORD '$POSTGRES_PASSWORD'"
@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
Docker's default configuration, this is Docker's default configuration, this is
effectively any other container on the same effectively any other container on the same
system. system.
Use "-e POSTGRES_PASSWORD=password" to set Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run". it in "docker run".
**************************************************** ****************************************************
EOWARN EOWARN
pass= pass=
authMethod=trust authMethod=trust
fi fi
: ${POSTGRES_USER:=postgres} : ${POSTGRES_USER:=postgres}
: ${POSTGRES_DB:=$POSTGRES_USER} : ${POSTGRES_DB:=$POSTGRES_USER}
@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
EOSQL EOSQL
echo echo
fi fi
if [ "$POSTGRES_USER" = 'postgres' ]; then if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER' op='ALTER'
else else
@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL EOSQL
echo echo
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
if [ -d /docker-entrypoint-initdb.d ]; then if [ -d /docker-entrypoint-initdb.d ]; then
for f in /docker-entrypoint-initdb.d/*.sh; do for f in /docker-entrypoint-initdb.d/*.sh; do
[ -f "$f" ] && . "$f" [ -f "$f" ] && . "$f"
done done
fi fi
fi fi
exec gosu postgres "$@" exec gosu postgres "$@"
fi fi

View File

@ -2,17 +2,19 @@
set -e set -e
if [ "$1" = 'postgres' ]; then if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA" chown -R postgres "$PGDATA"
chmod g+s /run/postgresql chmod g+s /run/postgresql
chown -R postgres:postgres /run/postgresql chown -R postgres:postgres /run/postgresql
if [ -z "$(ls -A "$PGDATA")" ]; then # look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
gosu postgres initdb gosu postgres initdb
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
# check password first so we can ouptut the warning before postgres # check password first so we can output the warning before postgres
# messes it up # messes it up
if [ "$POSTGRES_PASSWORD" ]; then if [ "$POSTGRES_PASSWORD" ]; then
pass="PASSWORD '$POSTGRES_PASSWORD'" pass="PASSWORD '$POSTGRES_PASSWORD'"
@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
Docker's default configuration, this is Docker's default configuration, this is
effectively any other container on the same effectively any other container on the same
system. system.
Use "-e POSTGRES_PASSWORD=password" to set Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run". it in "docker run".
**************************************************** ****************************************************
EOWARN EOWARN
pass= pass=
authMethod=trust authMethod=trust
fi fi
: ${POSTGRES_USER:=postgres} : ${POSTGRES_USER:=postgres}
: ${POSTGRES_DB:=$POSTGRES_USER} : ${POSTGRES_DB:=$POSTGRES_USER}
@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
EOSQL EOSQL
echo echo
fi fi
if [ "$POSTGRES_USER" = 'postgres' ]; then if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER' op='ALTER'
else else
@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL EOSQL
echo echo
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
if [ -d /docker-entrypoint-initdb.d ]; then if [ -d /docker-entrypoint-initdb.d ]; then
for f in /docker-entrypoint-initdb.d/*.sh; do for f in /docker-entrypoint-initdb.d/*.sh; do
[ -f "$f" ] && . "$f" [ -f "$f" ] && . "$f"
done done
fi fi
fi fi
exec gosu postgres "$@" exec gosu postgres "$@"
fi fi

View File

@ -2,17 +2,19 @@
set -e set -e
if [ "$1" = 'postgres' ]; then if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA" chown -R postgres "$PGDATA"
chmod g+s /run/postgresql chmod g+s /run/postgresql
chown -R postgres:postgres /run/postgresql chown -R postgres:postgres /run/postgresql
if [ -z "$(ls -A "$PGDATA")" ]; then # look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
gosu postgres initdb gosu postgres initdb
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
# check password first so we can ouptut the warning before postgres # check password first so we can output the warning before postgres
# messes it up # messes it up
if [ "$POSTGRES_PASSWORD" ]; then if [ "$POSTGRES_PASSWORD" ]; then
pass="PASSWORD '$POSTGRES_PASSWORD'" pass="PASSWORD '$POSTGRES_PASSWORD'"
@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
Docker's default configuration, this is Docker's default configuration, this is
effectively any other container on the same effectively any other container on the same
system. system.
Use "-e POSTGRES_PASSWORD=password" to set Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run". it in "docker run".
**************************************************** ****************************************************
EOWARN EOWARN
pass= pass=
authMethod=trust authMethod=trust
fi fi
: ${POSTGRES_USER:=postgres} : ${POSTGRES_USER:=postgres}
: ${POSTGRES_DB:=$POSTGRES_USER} : ${POSTGRES_DB:=$POSTGRES_USER}
@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
EOSQL EOSQL
echo echo
fi fi
if [ "$POSTGRES_USER" = 'postgres' ]; then if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER' op='ALTER'
else else
@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL EOSQL
echo echo
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
if [ -d /docker-entrypoint-initdb.d ]; then if [ -d /docker-entrypoint-initdb.d ]; then
for f in /docker-entrypoint-initdb.d/*.sh; do for f in /docker-entrypoint-initdb.d/*.sh; do
[ -f "$f" ] && . "$f" [ -f "$f" ] && . "$f"
done done
fi fi
fi fi
exec gosu postgres "$@" exec gosu postgres "$@"
fi fi

View File

@ -2,17 +2,19 @@
set -e set -e
if [ "$1" = 'postgres' ]; then if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA" chown -R postgres "$PGDATA"
chmod g+s /run/postgresql chmod g+s /run/postgresql
chown -R postgres:postgres /run/postgresql chown -R postgres:postgres /run/postgresql
if [ -z "$(ls -A "$PGDATA")" ]; then # look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
gosu postgres initdb gosu postgres initdb
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
# check password first so we can ouptut the warning before postgres # check password first so we can output the warning before postgres
# messes it up # messes it up
if [ "$POSTGRES_PASSWORD" ]; then if [ "$POSTGRES_PASSWORD" ]; then
pass="PASSWORD '$POSTGRES_PASSWORD'" pass="PASSWORD '$POSTGRES_PASSWORD'"
@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
Docker's default configuration, this is Docker's default configuration, this is
effectively any other container on the same effectively any other container on the same
system. system.
Use "-e POSTGRES_PASSWORD=password" to set Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run". it in "docker run".
**************************************************** ****************************************************
EOWARN EOWARN
pass= pass=
authMethod=trust authMethod=trust
fi fi
: ${POSTGRES_USER:=postgres} : ${POSTGRES_USER:=postgres}
: ${POSTGRES_DB:=$POSTGRES_USER} : ${POSTGRES_DB:=$POSTGRES_USER}
@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
EOSQL EOSQL
echo echo
fi fi
if [ "$POSTGRES_USER" = 'postgres' ]; then if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER' op='ALTER'
else else
@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL EOSQL
echo echo
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
if [ -d /docker-entrypoint-initdb.d ]; then if [ -d /docker-entrypoint-initdb.d ]; then
for f in /docker-entrypoint-initdb.d/*.sh; do for f in /docker-entrypoint-initdb.d/*.sh; do
[ -f "$f" ] && . "$f" [ -f "$f" ] && . "$f"
done done
fi fi
fi fi
exec gosu postgres "$@" exec gosu postgres "$@"
fi fi

View File

@ -2,17 +2,19 @@
set -e set -e
if [ "$1" = 'postgres' ]; then if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
chown -R postgres "$PGDATA" chown -R postgres "$PGDATA"
chmod g+s /run/postgresql chmod g+s /run/postgresql
chown -R postgres:postgres /run/postgresql chown -R postgres:postgres /run/postgresql
if [ -z "$(ls -A "$PGDATA")" ]; then # look specifically for PG_VERSION, as it is expected in the DB dir
if [ -s "$PGDATA/PG_VERSION" ]; then
gosu postgres initdb gosu postgres initdb
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
# check password first so we can ouptut the warning before postgres # check password first so we can output the warning before postgres
# messes it up # messes it up
if [ "$POSTGRES_PASSWORD" ]; then if [ "$POSTGRES_PASSWORD" ]; then
pass="PASSWORD '$POSTGRES_PASSWORD'" pass="PASSWORD '$POSTGRES_PASSWORD'"
@ -27,16 +29,16 @@ if [ "$1" = 'postgres' ]; then
Docker's default configuration, this is Docker's default configuration, this is
effectively any other container on the same effectively any other container on the same
system. system.
Use "-e POSTGRES_PASSWORD=password" to set Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run". it in "docker run".
**************************************************** ****************************************************
EOWARN EOWARN
pass= pass=
authMethod=trust authMethod=trust
fi fi
: ${POSTGRES_USER:=postgres} : ${POSTGRES_USER:=postgres}
: ${POSTGRES_DB:=$POSTGRES_USER} : ${POSTGRES_DB:=$POSTGRES_USER}
@ -46,7 +48,7 @@ if [ "$1" = 'postgres' ]; then
EOSQL EOSQL
echo echo
fi fi
if [ "$POSTGRES_USER" = 'postgres' ]; then if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER' op='ALTER'
else else
@ -57,16 +59,16 @@ if [ "$1" = 'postgres' ]; then
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ; $op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL EOSQL
echo echo
{ echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf { echo; echo "host all all 0.0.0.0/0 $authMethod"; } >> "$PGDATA"/pg_hba.conf
if [ -d /docker-entrypoint-initdb.d ]; then if [ -d /docker-entrypoint-initdb.d ]; then
for f in /docker-entrypoint-initdb.d/*.sh; do for f in /docker-entrypoint-initdb.d/*.sh; do
[ -f "$f" ] && . "$f" [ -f "$f" ] && . "$f"
done done
fi fi
fi fi
exec gosu postgres "$@" exec gosu postgres "$@"
fi fi