| 1 |
# |
| 2 |
# example Dockerfile for http://docs.docker.io/en/latest/examples/postgresql_service/ |
| 3 |
# |
| 4 |
|
| 5 |
FROM ubuntu |
| 6 |
MAINTAINER [email protected] |
| 7 |
|
| 8 |
# Add the PostgreSQL PGP key to verify their Debian packages. |
| 9 |
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc |
| 10 |
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 |
| 11 |
|
| 12 |
# Add PostgreSQL's repository. It contains the most recent stable release |
| 13 |
# of PostgreSQL, ``9.3``. |
| 14 |
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list |
| 15 |
|
| 16 |
# Update the Ubuntu and PostgreSQL repository indexes |
| 17 |
RUN apt-get update |
| 18 |
|
| 19 |
# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3 |
| 20 |
# There are some warnings (in red) that show up during the build. You can hide |
| 21 |
# them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive |
| 22 |
RUN apt-get -y -q install python-software-properties software-properties-common |
| 23 |
RUN apt-get -y -q install postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3 |
| 24 |
|
| 25 |
# Note: The official Debian and Ubuntu images automatically ``apt-get clean`` |
| 26 |
# after each ``apt-get`` |
| 27 |
|
| 28 |
# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed`` |
| 29 |
USER postgres |
| 30 |
|
| 31 |
# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and |
| 32 |
# then create a database `docker` owned by the ``docker`` role. |
| 33 |
# Note: here we use ``&&\`` to run commands one after the other - the ``\`` |
| 34 |
# allows the RUN command to span multiple lines. |
| 35 |
RUN /etc/init.d/postgresql start &&\ |
| 36 |
psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\ |
| 37 |
createdb -O docker docker |
| 38 |
|
| 39 |
# Adjust PostgreSQL configuration so that remote connections to the |
| 40 |
# database are possible. |
| 41 |
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf |
| 42 |
|
| 43 |
# And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf`` |
| 44 |
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf |
| 45 |
|
| 46 |
# Expose the PostgreSQL port |
| 47 |
EXPOSE 5432 |
| 48 |
|
| 49 |
# Add VOLUMEs to allow backup of config, logs and databases |
| 50 |
VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"] |
| 51 |
|
| 52 |
# Set the default command to run when starting the container |
| 53 |
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"] |