5 Commits

Author SHA1 Message Date
Sameer Naik 197d53e0a1 release 9.4-11 2015-12-13 14:55:54 +05:30
Sameer Naik 88208071b0 dockerfile: upgrade to sameersbn/ubuntu:14.04.20151213 2015-12-13 14:55:20 +05:30
Sameer Naik 38dc995884 added PG_PASSWORD variable to specify password for postgres user
Refer #43
2015-12-11 15:33:59 +05:30
Sameer Naik 116b158c1a release 9.4-10 2015-12-09 22:34:11 +05:30
Sameer Naik 60a249dd7d ensure required defaults are set at every start 2015-12-09 22:33:39 +05:30
6 changed files with 60 additions and 36 deletions
+3
View File
@@ -1,5 +1,8 @@
# Changelog # Changelog
**9.4-11**
- added `PG_PASSWORD` variable to specify password for `postgres` user
**9.4-9** **9.4-9**
- complete rewrite - complete rewrite
- `PSQL_TRUST_LOCALNET` config parameter renamed to `PG_TRUST_LOCALNET` - `PSQL_TRUST_LOCALNET` config parameter renamed to `PG_TRUST_LOCALNET`
+1 -1
View File
@@ -1,4 +1,4 @@
FROM sameersbn/ubuntu:14.04.20151117 FROM sameersbn/ubuntu:14.04.20151213
MAINTAINER sameer@damagehead.com MAINTAINER sameer@damagehead.com
ENV PG_APP_HOME="/etc/docker-postgresql"\ ENV PG_APP_HOME="/etc/docker-postgresql"\
+36 -19
View File
@@ -1,6 +1,6 @@
[![Circle CI](https://circleci.com/gh/sameersbn/docker-postgresql.svg?style=shield)](https://circleci.com/gh/sameersbn/docker-postgresql) [![Docker Repository on Quay.io](https://quay.io/repository/sameersbn/postgresql/status "Docker Repository on Quay.io")](https://quay.io/repository/sameersbn/postgresql) [![](https://badge.imagelayers.io/sameersbn/postgresql.svg)](https://imagelayers.io/?images=sameersbn/postgresql:latest 'Get your own badge on imagelayers.io') [![Circle CI](https://circleci.com/gh/sameersbn/docker-postgresql.svg?style=shield)](https://circleci.com/gh/sameersbn/docker-postgresql) [![Docker Repository on Quay.io](https://quay.io/repository/sameersbn/postgresql/status "Docker Repository on Quay.io")](https://quay.io/repository/sameersbn/postgresql) [![](https://badge.imagelayers.io/sameersbn/postgresql.svg)](https://imagelayers.io/?images=sameersbn/postgresql:latest 'Get your own badge on imagelayers.io')
# sameersbn/postgresql:9.4-9 # sameersbn/postgresql:9.4-11
- [Introduction](#introduction) - [Introduction](#introduction)
- [Contributing](#contributing) - [Contributing](#contributing)
@@ -10,6 +10,7 @@
- [Quickstart](#quickstart) - [Quickstart](#quickstart)
- [Persistence](#persistence) - [Persistence](#persistence)
- [Trusting local connections](#trusting-local-connections) - [Trusting local connections](#trusting-local-connections)
- [Setting `postgres` user password](#setting-postgres-user-password)
- [Creating database user](#creating-database-user) - [Creating database user](#creating-database-user)
- [Creating databases](#creating-databases) - [Creating databases](#creating-databases)
- [Enabling unaccent extension](#enabling-unaccent-extension) - [Enabling unaccent extension](#enabling-unaccent-extension)
@@ -60,7 +61,7 @@ Automated builds of the image are available on [Dockerhub](https://hub.docker.co
> **Note**: Builds are also available on [Quay.io](https://quay.io/repository/sameersbn/postgresql) > **Note**: Builds are also available on [Quay.io](https://quay.io/repository/sameersbn/postgresql)
```bash ```bash
docker pull sameersbn/postgresql:9.4-9 docker pull sameersbn/postgresql:9.4-11
``` ```
Alternatively you can build the image yourself. Alternatively you can build the image yourself.
@@ -77,7 +78,7 @@ Start PostgreSQL using:
docker run --name postgresql -itd --restart always \ docker run --name postgresql -itd --restart always \
--publish 5432:5432 \ --publish 5432:5432 \
--volume /srv/docker/postgresql:/var/lib/postgresql \ --volume /srv/docker/postgresql:/var/lib/postgresql \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
Login to the PostgreSQL server using: Login to the PostgreSQL server using:
@@ -108,13 +109,29 @@ By default connections to the PostgreSQL server need to authenticated using a pa
```bash ```bash
docker run --name postgresql -itd --restart always \ docker run --name postgresql -itd --restart always \
--env 'PG_TRUST_LOCALNET=true' \ --env 'PG_TRUST_LOCALNET=true' \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
> **Note** > **Note**
> >
> 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. > 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-11
```
> **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 ## Creating database user
A new PostgreSQL database user can be created by specifying the `DB_USER` and `DB_PASS` variables while starting the container. A new PostgreSQL database user can be created by specifying the `DB_USER` and `DB_PASS` variables while starting the container.
@@ -122,7 +139,7 @@ A new PostgreSQL database user can be created by specifying the `DB_USER` and `D
```bash ```bash
docker run --name postgresql -itd --restart always \ docker run --name postgresql -itd --restart always \
--env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' \ --env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
> **Notes** > **Notes**
@@ -139,7 +156,7 @@ A new PostgreSQL database can be created by specifying the `DB_NAME` variable wh
```bash ```bash
docker run --name postgresql -itd --restart always \ docker run --name postgresql -itd --restart always \
--env 'DB_NAME=dbname' \ --env 'DB_NAME=dbname' \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
Additionally, more than one database can be created by specifying a comma separated list of database names in `DB_NAME`. For example, the following command creates two new databases named `dbname1` and `dbname2`. Additionally, more than one database can be created by specifying a comma separated list of database names in `DB_NAME`. For example, the following command creates two new databases named `dbname1` and `dbname2`.
@@ -149,7 +166,7 @@ Additionally, more than one database can be created by specifying a comma separa
```bash ```bash
docker run --name postgresql -itd --restart always \ docker run --name postgresql -itd --restart always \
--env 'DB_NAME=dbname1,dbname2' \ --env 'DB_NAME=dbname1,dbname2' \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
# Enabling unaccent extension # Enabling unaccent extension
@@ -161,7 +178,7 @@ You can enable the unaccent extension on database(s) by specifying `DB_UNACCENT=
```bash ```bash
docker run --name postgresql -itd \ docker run --name postgresql -itd \
--env 'DB_NAME=dbname' --env 'DB_UNACCENT=true' \ --env 'DB_NAME=dbname' --env 'DB_UNACCENT=true' \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
*By default the unaccent extension is disabled* *By default the unaccent extension is disabled*
@@ -174,7 +191,7 @@ If the `DB_USER` and `DB_PASS` variables are specified along with the `DB_NAME`
docker run --name postgresql -itd --restart always \ docker run --name postgresql -itd --restart always \
--env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' \ --env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' \
--env 'DB_NAME=dbname1,dbname2' \ --env 'DB_NAME=dbname1,dbname2' \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
In the above example `dbuser` with be granted access to both the `dbname1` and `dbname2` databases. In the above example `dbuser` with be granted access to both the `dbname1` and `dbname2` databases.
@@ -186,7 +203,7 @@ Similar to the creation of a database user, a new PostgreSQL replication user ca
```bash ```bash
docker run --name postgresql -itd --restart always \ docker run --name postgresql -itd --restart always \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \ --env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
> **Notes** > **Notes**
@@ -208,7 +225,7 @@ Begin by creating the master node of our cluster:
docker run --name postgresql-master -itd --restart always \ docker run --name postgresql-master -itd --restart always \
--env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' --env 'DB_NAME=dbname' \ --env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' --env 'DB_NAME=dbname' \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \ --env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
Notice that no additional arguments are specified while starting the master node of the cluster. Notice that no additional arguments are specified while starting the master node of the cluster.
@@ -223,7 +240,7 @@ docker run --name postgresql-slave01 -itd --restart always \
--env 'REPLICATION_MODE=slave' --env 'REPLICATION_SSLMODE=prefer' \ --env 'REPLICATION_MODE=slave' --env 'REPLICATION_SSLMODE=prefer' \
--env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432' \ --env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432' \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \ --env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
*In the above command, we used docker links so that we can address the master node using the `master` alias in `REPLICATION_HOST`.* *In the above command, we used docker links so that we can address the master node using the `master` alias in `REPLICATION_HOST`.*
@@ -255,7 +272,7 @@ docker run --name postgresql-snapshot -itd --restart always \
--env 'REPLICATION_MODE=snapshot' --env 'REPLICATION_SSLMODE=prefer' \ --env 'REPLICATION_MODE=snapshot' --env 'REPLICATION_SSLMODE=prefer' \
--env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432' \ --env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432' \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \ --env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
The difference between a slave and a snapshot is that a slave is read-only and updated whenever the master data is updated (streaming replication), while a snapshot is read-write and is not updated after the initial snapshot of the data from the master. The difference between a slave and a snapshot is that a slave is read-only and updated whenever the master data is updated (streaming replication), while a snapshot is read-write and is not updated after the initial snapshot of the data from the master.
@@ -277,7 +294,7 @@ docker run --name postgresql-backup -it --rm \
--env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432' \ --env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432' \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \ --env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
--volume /srv/docker/backups/postgresql.$(date +%Y%m%d%H$M%S):/var/lib/postgresql \ --volume /srv/docker/backups/postgresql.$(date +%Y%m%d%H$M%S):/var/lib/postgresql \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
Once the backup is generated, the container will exit and the backup of the master data will be available at `/srv/docker/backups/postgresql.XXXXXXXXXXXX/`. Restoring the backup involves starting a container with the data in `/srv/docker/backups/postgresql.XXXXXXXXXXXX`. Once the backup is generated, the container will exit and the backup of the master data will be available at `/srv/docker/backups/postgresql.XXXXXXXXXXXX/`. Restoring the backup involves starting a container with the data in `/srv/docker/backups/postgresql.XXXXXXXXXXXX`.
@@ -288,7 +305,7 @@ You can customize the launch command of PostgreSQL server by specifying argument
```bash ```bash
docker run --name postgresql -itd --restart always \ docker run --name postgresql -itd --restart always \
sameersbn/postgresql:9.4-9 -c log_connections=on sameersbn/postgresql:9.4-11 -c log_connections=on
``` ```
Please refer to the documentation of [postgres](http://www.postgresql.org/docs/9.4/static/app-postgres.html) for the complete list of available options. Please refer to the documentation of [postgres](http://www.postgresql.org/docs/9.4/static/app-postgres.html) for the complete list of available options.
@@ -299,7 +316,7 @@ By default the PostgreSQL server logs are sent to the standard output. Using the
```bash ```bash
docker run --name postgresql -itd --restart always \ docker run --name postgresql -itd --restart always \
sameersbn/postgresql:9.4-9 -c logging_collector=on sameersbn/postgresql:9.4-11 -c logging_collector=on
``` ```
To access the PostgreSQL logs you can use `docker exec`. For example: To access the PostgreSQL logs you can use `docker exec`. For example:
@@ -321,7 +338,7 @@ For example, if you want to assign the `postgres` user of the container the UID
```bash ```bash
docker run --name postgresql -itd --restart always \ docker run --name postgresql -itd --restart always \
--env 'USERMAP_UID=999' --env 'USERMAP_GID=999' \ --env 'USERMAP_UID=999' --env 'USERMAP_GID=999' \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
# Maintenance # Maintenance
@@ -333,7 +350,7 @@ To upgrade to newer releases:
1. Download the updated Docker image: 1. Download the updated Docker image:
```bash ```bash
docker pull sameersbn/postgresql:9.4-9 docker pull sameersbn/postgresql:9.4-11
``` ```
2. Stop the currently running image: 2. Stop the currently running image:
@@ -353,7 +370,7 @@ To upgrade to newer releases:
```bash ```bash
docker run --name postgresql -itd \ docker run --name postgresql -itd \
[OPTIONS] \ [OPTIONS] \
sameersbn/postgresql:9.4-9 sameersbn/postgresql:9.4-11
``` ```
## Shell Access ## Shell Access
+1 -1
View File
@@ -1 +1 @@
9.4-9 9.4-11
+1 -1
View File
@@ -1,6 +1,6 @@
PostgreSQL: PostgreSQL:
restart: always restart: always
image: sameersbn/postgresql:9.4-9 image: sameersbn/postgresql:9.4-11
ports: ports:
- "5432:5432" - "5432:5432"
environment: environment:
+18 -14
View File
@@ -203,8 +203,12 @@ initialize_database() {
mv ${PG_HOME}/${PG_OLD_VERSION}.migrating ${PG_HOME}/${PG_OLD_VERSION} mv ${PG_HOME}/${PG_OLD_VERSION}.migrating ${PG_HOME}/${PG_OLD_VERSION}
fi fi
if [[ -n $PG_PASSWORD ]]; then
echo "${PG_PASSWORD}" > /tmp/pwfile
fi
exec_as_postgres ${PG_BINDIR}/initdb --pgdata=${PG_DATADIR} \ 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 if [[ -n ${PG_OLD_VERSION} ]]; then
PG_OLD_BINDIR=/usr/lib/postgresql/${PG_OLD_VERSION}/bin PG_OLD_BINDIR=/usr/lib/postgresql/${PG_OLD_VERSION}/bin
@@ -224,19 +228,6 @@ initialize_database() {
;; ;;
esac esac
# configure path to data_directory
set_postgresql_param "data_directory" "${PG_DATADIR}"
# configure logging
set_postgresql_param "log_directory" "${PG_LOGDIR}"
set_postgresql_param "log_filename" "postgresql-${PG_VERSION}-main.log"
# listen on all interfaces
set_postgresql_param "listen_addresses" "*"
# allow remote connections to postgresql database
set_hba_param "host all all 0.0.0.0/0 md5"
configure_hot_standby configure_hot_standby
# Change DSM from `posix' to `sysv' if we are inside an lx-brand container # Change DSM from `posix' to `sysv' if we are inside an lx-brand container
@@ -244,6 +235,19 @@ initialize_database() {
set_postgresql_param "dynamic_shared_memory_type" "sysv" set_postgresql_param "dynamic_shared_memory_type" "sysv"
fi fi
fi fi
# configure path to data_directory
set_postgresql_param "data_directory" "${PG_DATADIR}"
# configure logging
set_postgresql_param "log_directory" "${PG_LOGDIR}"
set_postgresql_param "log_filename" "postgresql-${PG_VERSION}-main.log"
# listen on all interfaces
set_postgresql_param "listen_addresses" "*"
# allow remote connections to postgresql database
set_hba_param "host all all 0.0.0.0/0 md5"
} }
trust_localnet() { trust_localnet() {