Skip to content

Commit 38dc995

Browse files
author
Sameer Naik
committed
added PG_PASSWORD variable to specify password for postgres user
Refer #43
1 parent 116b158 commit 38dc995

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
**latest**
4+
- added `PG_PASSWORD` variable to specify password for `postgres` user
5+
36
**9.4-9**
47
- complete rewrite
58
- `PSQL_TRUST_LOCALNET` config parameter renamed to `PG_TRUST_LOCALNET`

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [Quickstart](#quickstart)
1111
- [Persistence](#persistence)
1212
- [Trusting local connections](#trusting-local-connections)
13+
- [Setting `postgres` user password](#setting-postgres-user-password)
1314
- [Creating database user](#creating-database-user)
1415
- [Creating databases](#creating-databases)
1516
- [Enabling unaccent extension](#enabling-unaccent-extension)
@@ -115,6 +116,22 @@ docker run --name postgresql -itd --restart always \
115116
>
116117
> 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.
117118
119+
## Setting `postgres` user password
120+
121+
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.
122+
123+
```bash
124+
docker run --name postgresql -itd --restart always \
125+
--env 'PG_PASSWORD=passw0rd' \
126+
sameersbn/postgresql:9.4-10
127+
```
128+
129+
130+
> **Note**
131+
>
132+
> - When [persistence](#persistence) is in use, `PG_PASSWORD` is effective on the first run.
133+
> - This feature is only available in the `latest` and versions > `9.4-10`
134+
118135
## Creating database user
119136

120137
A new PostgreSQL database user can be created by specifying the `DB_USER` and `DB_PASS` variables while starting the container.

runtime/functions

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,12 @@ initialize_database() {
203203
mv ${PG_HOME}/${PG_OLD_VERSION}.migrating ${PG_HOME}/${PG_OLD_VERSION}
204204
fi
205205

206+
if [[ -n $PG_PASSWORD ]]; then
207+
echo "${PG_PASSWORD}" > /tmp/pwfile
208+
fi
209+
206210
exec_as_postgres ${PG_BINDIR}/initdb --pgdata=${PG_DATADIR} \
207-
--username=${PG_USER} --encoding=unicode --auth=trust >/dev/null
211+
--username=${PG_USER} --encoding=unicode --auth=trust ${PG_PASSWORD:+--pwfile=/tmp/pwfile} >/dev/null
208212

209213
if [[ -n ${PG_OLD_VERSION} ]]; then
210214
PG_OLD_BINDIR=/usr/lib/postgresql/${PG_OLD_VERSION}/bin

0 commit comments

Comments
 (0)