14 Commits

Author SHA1 Message Date
Sameer Naik 4d92cfc63e release 9.4-7 2015-10-23 12:02:37 +05:30
Sameer Naik 6d98301424 dockerfile: upgrade to quay.io/sameersbn/ubuntu:14.04.20151023 2015-10-23 12:02:15 +05:30
Sameer Naik 4fa09528b6 Merge branch 'sdusart-master' 2015-10-17 15:29:57 +05:30
Sameer Naik a443dfb2d9 Merge branch 'master' of https://github.com/sdusart/docker-postgresql into sdusart-master 2015-10-17 15:29:17 +05:30
Sameer Naik b75f1ea632 release 9.4-6 2015-10-13 14:35:46 +05:30
Sameer Naik a934d8131c dockerfile: upgrade to quay.io/sameersbn/ubuntu:14.04.20151013 2015-10-13 14:35:15 +05:30
Sameer Naik 8f331ff0b3 readme: added quay.io badge 2015-10-12 12:13:23 +05:30
Sameer Naik d933707cad Makefile: tag builds with quay.io/sameersbn/ prefix 2015-10-11 17:14:40 +05:30
Sameer Naik f5f7c094a1 hello quay.io, bye-bye hub.docker.com 2015-10-11 16:01:06 +05:30
Sameer Naik ba8244feea release 9.4-5 2015-10-11 13:28:43 +05:30
Sameer Naik fae08e9091 dockerfile: upgrade to quay.io/sameersbn/ubuntu:14.04.20151011 2015-10-11 13:28:11 +05:30
Sameer Naik eedfc6a1c9 set DEBIAN_FRONTEND=noninteractive env setting apt-get install lines 2015-10-10 23:05:12 +05:30
Sylvain Dusart 57f7f6597c Add an option to set the locale used for database creation
Using the DB_LOCALE environment variable (set by default to C), it is now
possible to set the --locale argument that is given to the initdb command.
This enables customization of LC_COLLATE and LC_TYPE for the databases.
2015-10-03 23:49:28 +02:00
Sylvain Dusart fbc06c1604 Protect usernames and database names in "CREATE ROLE", "CREATE DATABASE" and "GRANT ALL" requests
This enables to use "-" in for usernames or database names (eg myApp-client1).
2015-10-03 21:09:39 +02:00
5 changed files with 35 additions and 27 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
FROM sameersbn/ubuntu:14.04.20150825
FROM quay.io/sameersbn/ubuntu:14.04.20151023
MAINTAINER sameer@damagehead.com
ENV PG_VERSION=9.4 \
@@ -14,7 +14,7 @@ ENV PG_CONFDIR="/etc/postgresql/${PG_VERSION}/main" \
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main' > /etc/apt/sources.list.d/pgdg.list \
&& apt-get update \
&& apt-get install -y postgresql-${PG_VERSION} postgresql-client-${PG_VERSION} postgresql-contrib-${PG_VERSION} \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql-${PG_VERSION} postgresql-client-${PG_VERSION} postgresql-contrib-${PG_VERSION} \
&& rm -rf ${PG_HOME} \
&& rm -rf /var/lib/apt/lists/*
+2 -2
View File
@@ -1,7 +1,7 @@
all: build
build:
@docker build --tag=${USER}/postgresql .
@docker build --tag=quay.io/sameersbn/postgresql .
release: build
@docker build --tag=${USER}/postgresql:$(shell cat VERSION) .
@docker build --tag=quay.io/sameersbn/postgresql:$(shell cat VERSION) .
+18 -16
View File
@@ -1,4 +1,4 @@
[![Circle CI](https://circleci.com/gh/sameersbn/docker-postgresql.svg?style=svg)](https://circleci.com/gh/sameersbn/docker-postgresql)
[![Circle CI](https://circleci.com/gh/sameersbn/docker-postgresql.svg?style=svg)](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)
# Table of Contents
@@ -57,10 +57,10 @@ In your issue report please make sure you provide the following information:
# Installation
Pull the latest version of the image from the docker index. This is the recommended method of installation as it is easier to update image in the future. These builds are performed by the **Docker Trusted Build** service.
Automated builds of the image are available on [Quay.io](https://quay.io/repository/sameersbn/postgresql) and is the recommended method of installation.
```bash
docker pull sameersbn/postgresql:9.4-4
docker pull quay.io/sameersbn/postgresql:9.4-7
```
Alternately you can build the image yourself.
@@ -76,7 +76,7 @@ docker build -t="$USER/postgresql" .
Run the postgresql image
```bash
docker run --name postgresql -d sameersbn/postgresql:9.4-4
docker run --name postgresql -d quay.io/sameersbn/postgresql:9.4-7
```
The simplest way to login to the postgresql container as the administrative `postgres` user is to use the `docker exec` command to attach a new process to the running container and connect to the postgresql server over the unix socket.
@@ -100,7 +100,7 @@ The updated run command looks like this.
```bash
docker run --name postgresql -d \
-v /opt/postgresql/data:/var/lib/postgresql sameersbn/postgresql:9.4-4
-v /opt/postgresql/data:/var/lib/postgresql quay.io/sameersbn/postgresql:9.4-7
```
This will make sure that the data stored in the database is not lost when the image is stopped and started again.
@@ -114,7 +114,7 @@ To create a new user you should specify the `DB_USER` and `DB_PASS` variables. T
```bash
docker run --name postgresql -d \
-e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' \
sameersbn/postgresql:9.4-4
quay.io/sameersbn/postgresql:9.4-7
```
**NOTE**
@@ -125,7 +125,7 @@ Similarly, you can also create a new database by specifying the database name in
```bash
docker run --name postgresql -d \
-e 'DB_NAME=dbname' sameersbn/postgresql:9.4-4
-e 'DB_NAME=dbname' quay.io/sameersbn/postgresql:9.4-7
```
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).
@@ -133,7 +133,7 @@ You may also specify a comma separated list of database names in the `DB_NAME` v
```bash
docker run --name postgresql -d \
-e 'DB_NAME=dbname1,dbname2' \
sameersbn/postgresql:9.4-4
quay.io/sameersbn/postgresql:9.4-7
```
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).
@@ -143,11 +143,13 @@ For example,
```bash
docker run --name postgresql -d \
-e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' -e 'DB_NAME=dbname' \
sameersbn/postgresql:9.4-4
quay.io/sameersbn/postgresql:9.4-7
```
will create a user *dbuser* with the password *dbpass*. It will also create a database named *dbname* and the *dbuser* user will have full access to the *dbname* database.
The `DB_LOCALE` environment variable can be used to configure the locale used for database creation. Its default value is set to C.
The `PSQL_TRUST_LOCALNET` environment variable can be used to configure postgres to trust connections on the same network. This is handy for other containers to connect without authentication. To enable this behavior, set `PSQL_TRUST_LOCALNET` to `true`.
For example,
@@ -155,7 +157,7 @@ For example,
```bash
docker run --name postgresql -d \
-e 'PSQL_TRUST_LOCALNET=true' \
sameersbn/postgresql:9.4-4
quay.io/sameersbn/postgresql:9.4-7
```
This has the effect of adding the following to the `pg_hba.conf` file:
@@ -177,7 +179,7 @@ docker run --name='psql-master' -it --rm \
-e 'PSQL_MODE=master' -e 'PSQL_TRUST_LOCALNET=true' \
-e 'REPLICATION_USER=replicator' -e 'REPLICATION_PASS=replicatorpass' \
-e 'DB_NAME=dbname' -e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' \
sameersbn/postgresql:9.4-4
quay.io/sameersbn/postgresql:9.4-7
```
Create a streaming replication instance
@@ -188,7 +190,7 @@ docker run --name='psql-slave' -it --rm \
-e 'PSQL_MODE=slave' -e 'PSQL_TRUST_LOCALNET=true' \
-e 'REPLICATION_HOST=psql-master' -e 'REPLICATION_PORT=5432' \
-e 'REPLICATION_USER=replicator' -e 'REPLICATION_PASS=replicatorpass' \
sameersbn/postgresql:9.4-4
quay.io/sameersbn/postgresql:9.4-7
```
# Enable Unaccent (Search plain text with accent)
@@ -200,7 +202,7 @@ By default unaccent is configure to `false`
```bash
docker run --name postgresql -d \
-e 'DB_UNACCENT=true' \
sameersbn/postgresql:9.4-4
quay.io/sameersbn/postgresql:9.4-7
```
# Host UID / GID Mapping
@@ -212,7 +214,7 @@ Also the container processes seem to be executed as the host's user/group `[what
```bash
docker run --name=postgresql -it --rm [options] \
--env="USERMAP_UID=$(id -u postgres)" --env="USERMAP_GID=$(id -g postgres)" \
sameersbn/postgresql:9.4-4
quay.io/sameersbn/postgresql:9.4-7
```
@@ -229,13 +231,13 @@ docker stop postgresql
- **Step 2**: Update the docker image.
```bash
docker pull sameersbn/postgresql:9.4-4
docker pull quay.io/sameersbn/postgresql:9.4-7
```
- **Step 3**: Start the image
```bash
docker run --name postgresql -d [OPTIONS] sameersbn/postgresql:9.4-4
docker run --name postgresql -d [OPTIONS] quay.io/sameersbn/postgresql:9.4-7
```
# Shell Access
+1 -1
View File
@@ -1 +1 @@
9.4-4
9.4-7
+12 -6
View File
@@ -9,6 +9,7 @@ PSQL_TRUST_LOCALNET=${PSQL_TRUST_LOCALNET:-false}
DB_NAME=${DB_NAME:-}
DB_USER=${DB_USER:-}
DB_PASS=${DB_PASS:-}
DB_LOCALE=${DB_LOCALE:-C}
DB_UNACCENT=${DB_UNACCENT:false}
# by default postgresql will start up as a standalone instance.
@@ -146,9 +147,14 @@ EOF
# check if we need to perform data migration
PG_OLD_VERSION=$(find ${PG_HOME}/[0-9].[0-9]/main -maxdepth 1 -name PG_VERSION 2>/dev/null | sort -r | head -n1 | cut -d'/' -f5)
if [[ $DB_LOCALE != C ]]; then
echo "Generating required locale \"${DB_LOCALE}\"..."
locale-gen ${DB_LOCALE} >/dev/null
fi
echo "Initializing database..."
sudo -Hu ${PG_USER} ${PG_BINDIR}/initdb --pgdata=${PG_DATADIR} \
--username=${PG_USER} --encoding=unicode --auth=trust >/dev/null
--username=${PG_USER} --encoding=unicode --locale=${DB_LOCALE} --auth=trust >/dev/null
fi
fi
@@ -165,7 +171,7 @@ if [[ -n ${PG_OLD_VERSION} ]]; then
echo "Installing postgresql-${PG_OLD_VERSION}..."
apt-get update
apt-get install postgresql-${PG_OLD_VERSION} postgresql-client-${PG_OLD_VERSION}
DEBIAN_FRONTEND=noninteractive apt-get install postgresql-${PG_OLD_VERSION} postgresql-client-${PG_OLD_VERSION}
rm -rf /var/lib/apt/lists/*
# migrate ${PG_OLD_VERSION} data
@@ -188,7 +194,7 @@ if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
DB_USER=
else
echo "Creating user \"${REPLICATION_USER}\"..."
echo "CREATE ROLE ${REPLICATION_USER} WITH REPLICATION LOGIN ENCRYPTED PASSWORD '${REPLICATION_PASS}';" |
echo "CREATE ROLE \"${REPLICATION_USER}\" WITH REPLICATION LOGIN ENCRYPTED PASSWORD '${REPLICATION_PASS}';" |
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
fi
@@ -203,7 +209,7 @@ if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
DB_USER=
else
echo "Creating user \"${DB_USER}\"..."
echo "CREATE ROLE ${DB_USER} with LOGIN CREATEDB PASSWORD '${DB_PASS}';" |
echo "CREATE ROLE \"${DB_USER}\" with LOGIN CREATEDB PASSWORD '${DB_PASS}';" |
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
fi
@@ -212,7 +218,7 @@ if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
if [[ -n ${DB_NAME} ]]; then
for db in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do
echo "Creating database \"${db}\"..."
echo "CREATE DATABASE ${db};" | \
echo "CREATE DATABASE \"${db}\";" | \
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
@@ -225,7 +231,7 @@ if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
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};" |
echo "GRANT ALL PRIVILEGES ON DATABASE \"${db}\" to \"${DB_USER}\";" |
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
fi