Public Repository

Last pushed: 2 years ago
Short Description
PostgreSQL 9.5
Full Description

FROM ubuntu:14.04


Add the PostgreSQL PGP key to verify their Debian packages.

apt-get update && \
apt-get install -y wget && \
wget --quiet -O - | sudo apt-key add - && \
apt-get update &&\
echo "deb trusty-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
apt-get update && \
apt-get install -y python-software-properties software-properties-common \
postgresql-${POSTGRESQL_VERSION} postgresql-client-${POSTGRESQL_VERSION} \

Run the rest of the commands as the postgres user created by the postgres-9.3 package when it was apt-get installed

USER postgres

Create a PostgreSQL role named docker with docker as the password and

then create a database docker owned by the docker role.

Note: here we use &&\ to run commands one after the other - the \

allows the RUN command to span multiple lines.

RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\
createdb -O docker docker

Adjust PostgreSQL configuration so that remote connections to the

database are possible.

RUN echo "host all all md5" >> /etc/postgresql/${POSTGRESQL_VERSION}/main/pg_hba.conf

And add listen_addresses to /etc/postgresql/${POSTGRESQL_VERSION}/main/postgresql.conf

RUN echo "listen_addresses='*'" >> /etc/postgresql/${POSTGRESQL_VERSION}/main/postgresql.conf

Expose the PostgreSQL port


Add VOLUMEs to allow backup of config, logs and databases

VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]

Set the default command to run when starting the container

CMD /usr/lib/postgresql/${POSTGRESQL_VERSION}/bin/postgres -D /var/lib/postgresql/${POSTGRESQL_VERSION}/main -c config_file=/etc/postgresql/${POSTGRESQL_VERSION}/main/postgresql.conf

Docker Pull Command