Make a proper data mount for Postgres

This commit is contained in:
Disassembler 2018-01-27 14:44:44 +01:00
parent 045c47a12f
commit 7970306105
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
4 changed files with 9 additions and 9 deletions

View File

@ -6,19 +6,19 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/postgres
docker build -t postgres ${SOURCE_DIR} docker build -t postgres ${SOURCE_DIR}
# Create Postgres instance # Create Postgres instance
mkdir /srv/postgres mkdir -p /srv/postgres/data
chown -R 5432:5432 /srv/postgres chown -R 5432:5432 /srv/postgres/data
chmod 700 /srv/postgres chmod 700 /srv/postgres/data
docker run --rm --name postgres -h postgres -v /srv/postgres:/var/lib/postgresql postgres initdb -D /var/lib/postgresql docker run --rm --name postgres -h postgres -v /srv/postgres/data:/var/lib/postgresql postgres initdb -D /var/lib/postgresql
# Configure Postgres # Configure Postgres
cp ${SOURCE_DIR}/srv/postgres/postgresql.conf /srv/postgres/postgresql.conf cp ${SOURCE_DIR}/srv/postgres/data/postgresql.conf /srv/postgres/data/postgresql.conf
cp ${SOURCE_DIR}/srv/postgres/pg_hba.conf /srv/postgres/pg_hba.conf cp ${SOURCE_DIR}/srv/postgres/data/pg_hba.conf /srv/postgres/data/pg_hba.conf
# Enable query logging. Only if the DEBUG environment variable is set # Enable query logging. Only if the DEBUG environment variable is set
if [ ${DEBUG:-0} -eq 1 ]; then if [ ${DEBUG:-0} -eq 1 ]; then
sed -i 's/^#log_destination/log_destination/' /srv/postgres/postgresql.conf sed -i 's/^#log_destination/log_destination/' /srv/postgres/data/postgresql.conf
sed -i 's/^#log_statement/log_statement/' /srv/postgres/postgresql.conf sed -i 's/^#log_statement/log_statement/' /srv/postgres/data/postgresql.conf
fi fi
# Configure Postgres service # Configure Postgres service

View File

@ -11,7 +11,7 @@ start() {
/usr/bin/docker run -d --rm \ /usr/bin/docker run -d --rm \
--name postgres \ --name postgres \
-h postgres \ -h postgres \
-v /srv/postgres:/var/lib/postgresql \ -v /srv/postgres/data:/var/lib/postgresql \
postgres postgres
} }