mirror of
https://github.com/wassname/docker-postgresql.git
synced 2026-06-27 18:42:46 +08:00
added PG_PASSWORD variable to specify password for postgres user
Refer #43
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
**latest**
|
||||
- added `PG_PASSWORD` variable to specify password for `postgres` user
|
||||
|
||||
**9.4-9**
|
||||
- complete rewrite
|
||||
- `PSQL_TRUST_LOCALNET` config parameter renamed to `PG_TRUST_LOCALNET`
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
- [Quickstart](#quickstart)
|
||||
- [Persistence](#persistence)
|
||||
- [Trusting local connections](#trusting-local-connections)
|
||||
- [Setting `postgres` user password](#setting-postgres-user-password)
|
||||
- [Creating database user](#creating-database-user)
|
||||
- [Creating databases](#creating-databases)
|
||||
- [Enabling unaccent extension](#enabling-unaccent-extension)
|
||||
@@ -115,6 +116,22 @@ docker run --name postgresql -itd --restart always \
|
||||
>
|
||||
> The local network here is network to which the container is attached. This has different meanings depending on the `--net` parameter specified while starting the container. In the default configuration, this parameter would trust connections from other containers on the `docker0` bridge.
|
||||
|
||||
## Setting `postgres` user password
|
||||
|
||||
By default the `postgres` user is not assigned a password and as a result you can only login to the PostgreSQL server locally. If you wish to login remotely to the PostgreSQL server as the `postgres` user, you will need to assign a password for the user using the `PG_PASSWORD` variable.
|
||||
|
||||
```bash
|
||||
docker run --name postgresql -itd --restart always \
|
||||
--env 'PG_PASSWORD=passw0rd' \
|
||||
sameersbn/postgresql:9.4-10
|
||||
```
|
||||
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> - When [persistence](#persistence) is in use, `PG_PASSWORD` is effective on the first run.
|
||||
> - This feature is only available in the `latest` and versions > `9.4-10`
|
||||
|
||||
## Creating database user
|
||||
|
||||
A new PostgreSQL database user can be created by specifying the `DB_USER` and `DB_PASS` variables while starting the container.
|
||||
|
||||
+5
-1
@@ -203,8 +203,12 @@ initialize_database() {
|
||||
mv ${PG_HOME}/${PG_OLD_VERSION}.migrating ${PG_HOME}/${PG_OLD_VERSION}
|
||||
fi
|
||||
|
||||
if [[ -n $PG_PASSWORD ]]; then
|
||||
echo "${PG_PASSWORD}" > /tmp/pwfile
|
||||
fi
|
||||
|
||||
exec_as_postgres ${PG_BINDIR}/initdb --pgdata=${PG_DATADIR} \
|
||||
--username=${PG_USER} --encoding=unicode --auth=trust >/dev/null
|
||||
--username=${PG_USER} --encoding=unicode --auth=trust ${PG_PASSWORD:+--pwfile=/tmp/pwfile} >/dev/null
|
||||
|
||||
if [[ -n ${PG_OLD_VERSION} ]]; then
|
||||
PG_OLD_BINDIR=/usr/lib/postgresql/${PG_OLD_VERSION}/bin
|
||||
|
||||
Reference in New Issue
Block a user