├── Dockerfile ├── LICENSE ├── README.md └── docker-compose.yml /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | MAINTAINER Andrea Grandi 3 | 4 | # Add the PostgreSQL PGP key to verify their Debian packages. 5 | # It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc 6 | RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 7 | 8 | # Add PostgreSQL's repository. It contains the most recent stable release 9 | # of PostgreSQL, ``9.3``. 10 | RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list 11 | 12 | # Update the Ubuntu and PostgreSQL repository indexes and install ``python-software-properties``, 13 | # ``software-properties-common`` and PostgreSQL 9.3 14 | # There are some warnings (in red) that show up during the build. You can hide 15 | # them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive 16 | RUN apt-get update && apt-get -y -q install python-software-properties software-properties-common \ 17 | && apt-get -y -q install postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3 18 | 19 | USER postgres 20 | 21 | RUN /etc/init.d/postgresql start \ 22 | && psql --command "CREATE USER pguser WITH SUPERUSER PASSWORD 'pguser';" \ 23 | && createdb -O pguser pgdb 24 | 25 | USER root 26 | 27 | # Adjust PostgreSQL configuration so that remote connections to the 28 | # database are possible. 29 | RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf 30 | 31 | # And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf`` 32 | RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf 33 | 34 | # Expose the PostgreSQL port 35 | EXPOSE 5432 36 | 37 | RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql 38 | 39 | # Add VOLUMEs to allow backup of config, logs and databases 40 | VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"] 41 | 42 | USER postgres 43 | 44 | # Set the default command to run when starting the container 45 | 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"] 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Andrea Grandi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # postgresql-docker 2 | 3 | Docker image for PostgreSQL 4 | 5 | **Get it running:** 6 | 7 | ``$ docker-compose up`` 8 | 9 | **Testing the running PostgreSQL** 10 | 11 | To test the running container we can use any client, even the commandline one: 12 | 13 | 14 | ``psql -h localhost -p 5432 -U pguser -W pgdb`` 15 | 16 | When you are prompted for password, type: pguser 17 | 18 | _Please note that localhost is only valid if you are running Docker on Ubuntu. If you are an OSX user, you need to discover the correct ip using: boot2docker ip_ -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | dbdata: 2 | image: andreagrandi/postgresql:9.3 3 | volumes: 4 | - /var/lib/postgresql 5 | command: true 6 | 7 | db: 8 | image: andreagrandi/postgresql:9.3 9 | volumes_from: 10 | - dbdata 11 | ports: 12 | - "5432:5432" 13 | --------------------------------------------------------------------------------