mirror of
https://github.com/wassname/docker-postgresql.git
synced 2026-06-28 22:36:20 +08:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b75f1ea632 | |||
| a934d8131c | |||
| 8f331ff0b3 | |||
| d933707cad | |||
| f5f7c094a1 | |||
| ba8244feea | |||
| fae08e9091 | |||
| eedfc6a1c9 | |||
| 47f6fd61a7 | |||
| b3d5862cd1 | |||
| 7da82b6646 | |||
| 9ca966eb1f | |||
| da0fb3dc36 | |||
| 306f915aaf | |||
| fd3794fa03 | |||
| 3c5e076101 | |||
| 17c826882a | |||
| c37ff75c41 | |||
| 2c1b7a1519 | |||
| 7bb94d25f9 | |||
| 28316a48f4 |
+9
-7
@@ -1,9 +1,11 @@
|
||||
FROM sameersbn/ubuntu:14.04.20150712
|
||||
FROM quay.io/sameersbn/ubuntu:14.04.20151013
|
||||
MAINTAINER sameer@damagehead.com
|
||||
|
||||
ENV PG_VERSION=9.4 \
|
||||
PG_USER=postgres \
|
||||
PG_HOME="/var/lib/postgresql"
|
||||
PG_HOME=/var/lib/postgresql \
|
||||
PG_RUNDIR=/run/postgresql \
|
||||
PG_LOGDIR=/var/log/postgresql
|
||||
|
||||
ENV PG_CONFDIR="/etc/postgresql/${PG_VERSION}/main" \
|
||||
PG_BINDIR="/usr/lib/postgresql/${PG_VERSION}/bin" \
|
||||
@@ -12,13 +14,13 @@ 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/*
|
||||
|
||||
COPY start /start
|
||||
RUN chmod 755 /start
|
||||
COPY entrypoint.sh /sbin/entrypoint.sh
|
||||
RUN chmod 755 /sbin/entrypoint.sh
|
||||
|
||||
EXPOSE 5432/tcp
|
||||
VOLUME ["${PG_HOME}", "/run/postgresql"]
|
||||
CMD ["/start"]
|
||||
VOLUME ["${PG_HOME}", "${PG_RUNDIR}"]
|
||||
CMD ["/sbin/entrypoint.sh"]
|
||||
|
||||
@@ -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) .
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[](https://circleci.com/gh/sameersbn/docker-postgresql)
|
||||
[](https://circleci.com/gh/sameersbn/docker-postgresql) [](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-2
|
||||
docker pull quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
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-2
|
||||
docker run --name postgresql -d quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
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-2
|
||||
-v /opt/postgresql/data:/var/lib/postgresql quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
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-2
|
||||
quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
**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-2
|
||||
-e 'DB_NAME=dbname' quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
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-2
|
||||
quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
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,7 +143,7 @@ For example,
|
||||
```bash
|
||||
docker run --name postgresql -d \
|
||||
-e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' -e 'DB_NAME=dbname' \
|
||||
sameersbn/postgresql:9.4-2
|
||||
quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
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.
|
||||
@@ -155,7 +155,7 @@ For example,
|
||||
```bash
|
||||
docker run --name postgresql -d \
|
||||
-e 'PSQL_TRUST_LOCALNET=true' \
|
||||
sameersbn/postgresql:9.4-2
|
||||
quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
This has the effect of adding the following to the `pg_hba.conf` file:
|
||||
@@ -177,7 +177,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-2
|
||||
quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
Create a streaming replication instance
|
||||
@@ -188,7 +188,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-2
|
||||
quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
# Enable Unaccent (Search plain text with accent)
|
||||
@@ -200,7 +200,7 @@ By default unaccent is configure to `false`
|
||||
```bash
|
||||
docker run --name postgresql -d \
|
||||
-e 'DB_UNACCENT=true' \
|
||||
sameersbn/postgresql:9.4-2
|
||||
quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
# Host UID / GID Mapping
|
||||
@@ -212,7 +212,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-2
|
||||
quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
|
||||
@@ -229,13 +229,13 @@ docker stop postgresql
|
||||
- **Step 2**: Update the docker image.
|
||||
|
||||
```bash
|
||||
docker pull sameersbn/postgresql:9.4-2
|
||||
docker pull quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
- **Step 3**: Start the image
|
||||
|
||||
```bash
|
||||
docker run --name postgresql -d [OPTIONS] sameersbn/postgresql:9.4-2
|
||||
docker run --name postgresql -d [OPTIONS] quay.io/sameersbn/postgresql:9.4-6
|
||||
```
|
||||
|
||||
# Shell Access
|
||||
|
||||
+42
-20
@@ -24,33 +24,55 @@ REPLICATION_PORT=${REPLICATION_PORT:-5432}
|
||||
# set this env variable to "require" to enable encryption and "verify-full" for verification.
|
||||
PSQL_SSLMODE=${PSQL_SSLMODE:-disable}
|
||||
|
||||
## Adapt uid and gid for ${PG_USER}:${PG_USER}
|
||||
USERMAP_ORIG_UID=$(id -u ${PG_USER})
|
||||
USERMAP_ORIG_GID=$(id -g ${PG_USER})
|
||||
USERMAP_GID=${USERMAP_GID:-${USERMAP_UID:-$USERMAP_ORIG_GID}}
|
||||
USERMAP_UID=${USERMAP_UID:-$USERMAP_ORIG_UID}
|
||||
if [[ ${USERMAP_UID} != ${USERMAP_ORIG_UID} ]] || [[ ${USERMAP_GID} != ${USERMAP_ORIG_GID} ]]; then
|
||||
echo "Adapting uid and gid for ${PG_USER}:${PG_USER} to $USERMAP_UID:$USERMAP_GID"
|
||||
groupmod -g ${USERMAP_GID} ${PG_USER}
|
||||
sed -i -e "s/:${USERMAP_ORIG_UID}:${USERMAP_GID}:/:${USERMAP_UID}:${USERMAP_GID}:/" /etc/passwd
|
||||
fi
|
||||
map_postgres_uid() {
|
||||
USERMAP_ORIG_UID=$(id -u ${PG_USER})
|
||||
USERMAP_ORIG_GID=$(id -g ${PG_USER})
|
||||
USERMAP_GID=${USERMAP_GID:-${USERMAP_UID:-$USERMAP_ORIG_GID}}
|
||||
USERMAP_UID=${USERMAP_UID:-$USERMAP_ORIG_UID}
|
||||
if [[ ${USERMAP_UID} != ${USERMAP_ORIG_UID} ]] || [[ ${USERMAP_GID} != ${USERMAP_ORIG_GID} ]]; then
|
||||
echo "Adapting uid and gid for ${PG_USER}:${PG_USER} to $USERMAP_UID:$USERMAP_GID"
|
||||
groupmod -g ${USERMAP_GID} ${PG_USER}
|
||||
sed -i -e "s/:${USERMAP_ORIG_UID}:${USERMAP_GID}:/:${USERMAP_UID}:${USERMAP_GID}:/" /etc/passwd
|
||||
fi
|
||||
}
|
||||
|
||||
create_data_dir() {
|
||||
mkdir -p ${PG_HOME}
|
||||
chmod -R 0700 ${PG_HOME}
|
||||
chown -R ${PG_USER}:${PG_USER} ${PG_HOME}
|
||||
}
|
||||
|
||||
create_log_dir() {
|
||||
mkdir -p ${PG_LOGDIR}
|
||||
chmod -R 1775 ${PG_LOGDIR}
|
||||
chown -R root:${PG_USER} ${PG_LOGDIR}
|
||||
}
|
||||
|
||||
create_run_dir() {
|
||||
mkdir -p ${PG_RUNDIR} ${PG_RUNDIR}/${PG_VERSION}-main.pg_stat_tmp
|
||||
chmod -R 0755 ${PG_RUNDIR}
|
||||
chmod g+s ${PG_RUNDIR}
|
||||
chown -R ${PG_USER}:${PG_USER} ${PG_RUNDIR}
|
||||
}
|
||||
|
||||
map_postgres_uid
|
||||
create_data_dir
|
||||
create_log_dir
|
||||
create_run_dir
|
||||
|
||||
# fix ownership of ${PG_CONFDIR} (may be necessary if USERMAP_* was set)
|
||||
chown -R ${PG_USER}:${PG_USER} ${PG_CONFDIR}
|
||||
|
||||
# fix permissions and ownership of ${PG_HOME}
|
||||
mkdir -p -m 0700 ${PG_HOME}
|
||||
chown -R ${PG_USER}:${PG_USER} ${PG_HOME}
|
||||
|
||||
# fix permissions and ownership of /run/postgresql
|
||||
mkdir -p -m 0755 /run/postgresql /run/postgresql/${PG_VERSION}-main.pg_stat_tmp
|
||||
chown -R ${PG_USER}:${PG_USER} /run/postgresql
|
||||
chmod g+s /run/postgresql
|
||||
|
||||
if [[ ${PSQL_SSLMODE} == disable ]]; then
|
||||
sed 's/ssl = true/#ssl = true/' -i ${PG_CONFDIR}/postgresql.conf
|
||||
fi
|
||||
|
||||
# Change DSM from `posix' to `sysv' if we are inside an lx-brand container
|
||||
if [[ $(uname -v) == "BrandZ virtual linux" ]]; then
|
||||
sed 's/\(dynamic_shared_memory_type = \)posix/\1sysv/' \
|
||||
-i ${PG_CONFDIR}/postgresql.conf
|
||||
fi
|
||||
|
||||
# listen on all interfaces
|
||||
cat >> ${PG_CONFDIR}/postgresql.conf <<EOF
|
||||
listen_addresses = '*'
|
||||
@@ -143,7 +165,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
|
||||
Reference in New Issue
Block a user