mirror of
https://github.com/wassname/docker-postgresql.git
synced 2026-09-10 12:00:18 +08:00
@@ -131,7 +131,14 @@ docker run --name postgresql -d \
|
|||||||
-e 'DB_NAME=dbname' sameersbn/postgresql:9.1-1
|
-e 'DB_NAME=dbname' sameersbn/postgresql:9.1-1
|
||||||
```
|
```
|
||||||
|
|
||||||
If the `DB_USER` and `DB_PASS` variables are also specified while creating the database, then the user is granted access to the database.
|
You may also specify a comma separated list of database names in the `DB_NAME` variable. The following command creates two new databases named *dbname1* and *dbname2 (p.s. this feature is only available in releases greater than 9.1-1)*
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name postgresql -d \
|
||||||
|
-e 'DB_NAME=dbname1,dbname2' sameersbn/postgresql:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
If the `DB_USER` and `DB_PASS` variables are also specified while creating the database, then the user is granted access to the database(s).
|
||||||
|
|
||||||
For example,
|
For example,
|
||||||
|
|
||||||
|
|||||||
@@ -69,17 +69,19 @@ if [ -n "${DB_USER}" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${DB_NAME}" ]; then
|
if [ -n "${DB_NAME}" ]; then
|
||||||
echo "Creating database \"${DB_NAME}\"..."
|
for db in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do
|
||||||
echo "CREATE DATABASE ${DB_NAME};" | \
|
echo "Creating database \"${db}\"..."
|
||||||
sudo -u postgres -H ${PG_BINDIR}/postgres --single \
|
echo "CREATE DATABASE ${db};" | \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null 2>&1
|
|
||||||
|
|
||||||
if [ -n "${DB_USER}" ]; then
|
|
||||||
echo "Granting access to database \"${DB_NAME}\" for user \"${DB_USER}\"..."
|
|
||||||
echo "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} to ${DB_USER};" |
|
|
||||||
sudo -u postgres -H ${PG_BINDIR}/postgres --single \
|
sudo -u postgres -H ${PG_BINDIR}/postgres --single \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null 2>&1
|
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null 2>&1
|
||||||
fi
|
|
||||||
|
if [ -n "${DB_USER}" ]; then
|
||||||
|
echo "Granting access to database \"${db}\" for user \"${DB_USER}\"..."
|
||||||
|
echo "GRANT ALL PRIVILEGES ON DATABASE ${db} to ${DB_USER};" |
|
||||||
|
sudo -u postgres -H ${PG_BINDIR}/postgres --single \
|
||||||
|
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Starting PostgreSQL server..."
|
echo "Starting PostgreSQL server..."
|
||||||
|
|||||||
Reference in New Issue
Block a user