Public | Automated Build

Last pushed: 3 years ago
Short Description
Short description is empty for this repo.
Full Description

docker-postgresql

Forked from sameersbn/docker-postgresql to use Debian Jessie instead of Ubuntu.

The documentation below is modified from the original README by @sameersbn.

Installation

Using pre-built image

docker pull erikano/docker-postgresql:9.4

Building it yourself

mkdir -p ~/src/github.com/erikano/
cd ~/src/github.com/erikano/
git clone https://github.com/erikano/docker-postgresql.git
cd docker-postgresql
docker build -t="erikano/docker-postgresql:$( git rev-parse --abbrev-ref HEAD )" .

Configuration

Data persistence

For data persistence a volume should be mounted at /var/lib/postgresql within the container.

Create the directory on the host.

sudo mkdir -p /opt/postgresql/data

If using SELinux, change the security context of the mount point.

sudo chcon -Rt svirt_sandbox_file_t /opt/postgresql/data

Usage

Running

Default

Data is not persisted. Use only where loss of data doesn't matter.

docker run --name postgresql -d erikano/docker-postgresql:9.4

Creating user and database at launch

Data is not persisted. Use only where loss of data doesn't matter.

Replace dbuser, dbpass and dbname with
the username, password and database name
you wish to have created.

docker run --name postgresql -d \
  -e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' \
  -e 'DB_NAME=dbname' \
  erikano/docker-postgresql:9.4

The user will be granted access to the database.

Bind-mounted volume for data persistence

I.e. what you almost certainly want to be doing in production. Combine with
creating user and database at launch
if applicable.

docker run --name postgresql -d \
  -v /opt/postgresql/data:/var/lib/postgresql \
  erikano/docker-postgresql:9.4

Connecting to the container

Executing psql as postgres within the container

docker exec -it postgresql sudo -u postgres -i psql

Executing bash as root within the container

Useful for debugging and maintenance.

docker exec -it postgresql bash

Please note that the Debian image is quite slim so you will find
that some utilities you might expect to have, such as man and netstat,
are missing.

For a development container, it could be a good idea to modify the
Dockerfile to install utilities you need for debugging.
Just ensure that your development and production containers
don't diverge too much from one another or you'll end up with
things which worked in dev but break in prod ;)

Mounting postgresql Unix Domain Socket in other containers

Illustrative example.

docker run -it --rm --volumes-from=postgresql debian:jessie \
  ls -al /var/run/postgresql

Upgrading the container

Please note that these instructions apply to updating containers
for the same versions of PostgreSQL. That is, this only applies
for changes to the Dockerfile and surrounding parts.

Pre-built image

docker pull erikano/docker-postgresql:9.4 \
&& docker stop postgresql \
&& docker rm postgresql

Start the new image by issuing the usual run command.

Self-built image

cd ~/src/github.com/erikano/docker-postgresql/ \
&& git pull \
&& docker build -t="erikano/docker-postgresql:$( git rev-parse --abbrev-ref HEAD )" . \
&& docker stop postgresql \
&& docker rm postgresql

Start the new image by issuing the usual run command.

Docker Pull Command
Owner
erikano
Source Repository