|
1 |
| -# vim:set ft=dockerfile: |
2 |
| -FROM debian:jessie |
| 1 | +# |
| 2 | +# example Dockerfile for https://docs.docker.com/examples/postgresql_service/ |
| 3 | +# |
3 | 4 |
|
4 |
| -# explicitly set user/group IDs |
5 |
| -RUN groupadd -r postgres --gid=999 && useradd -r -g postgres --uid=999 postgres |
| 5 | +FROM ubuntu |
| 6 | + |
6 | 7 |
|
7 |
| -# grab gosu for easy step-down from root |
8 |
| -ENV GOSU_VERSION 1.7 |
9 |
| -RUN set -x \ |
10 |
| - && apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \ |
11 |
| - && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \ |
12 |
| - && wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \ |
13 |
| - && export GNUPGHOME="$(mktemp -d)" \ |
14 |
| - && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ |
15 |
| - && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \ |
16 |
| - && rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \ |
17 |
| - && chmod +x /usr/local/bin/gosu \ |
18 |
| - && gosu nobody true \ |
19 |
| - && apt-get purge -y --auto-remove ca-certificates wget |
| 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://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 |
20 | 11 |
|
21 |
| -# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default |
22 |
| -RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \ |
23 |
| - && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 |
24 |
| -ENV LANG en_US.utf8 |
| 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 |
25 | 15 |
|
26 |
| -RUN mkdir /docker-entrypoint-initdb.d |
| 16 | +# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3 |
| 17 | +# There are some warnings (in red) that show up during the build. You can hide |
| 18 | +# them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive |
| 19 | +RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3 |
27 | 20 |
|
28 |
| -RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 |
| 21 | +# Note: The official Debian and Ubuntu images automatically ``apt-get clean`` |
| 22 | +# after each ``apt-get`` |
29 | 23 |
|
30 |
| -ENV PG_MAJOR 9.3 |
31 |
| -ENV PG_VERSION 9.3.11-1.pgdg80+1 |
| 24 | +# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed`` |
| 25 | +USER postgres |
32 | 26 |
|
33 |
| -RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list |
| 27 | +# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and |
| 28 | +# then create a database `docker` owned by the ``docker`` role. |
| 29 | +# Note: here we use ``&&\`` to run commands one after the other - the ``\`` |
| 30 | +# allows the RUN command to span multiple lines. |
| 31 | +RUN /etc/init.d/postgresql start &&\ |
| 32 | + psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\ |
| 33 | + createdb -O docker docker |
34 | 34 |
|
35 |
| -RUN apt-get update \ |
36 |
| - && apt-get install -y postgresql-common \ |
37 |
| - && sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \ |
38 |
| - && apt-get install -y \ |
39 |
| - postgresql-$PG_MAJOR=$PG_VERSION \ |
40 |
| - postgresql-contrib-$PG_MAJOR=$PG_VERSION \ |
41 |
| - && rm -rf /var/lib/apt/lists/* |
| 35 | +# Adjust PostgreSQL configuration so that remote connections to the |
| 36 | +# database are possible. |
| 37 | +RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf |
42 | 38 |
|
43 |
| -# make the sample config easier to munge (and "correct by default") |
44 |
| -RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/postgresql/ \ |
45 |
| - && ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \ |
46 |
| - && sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample |
| 39 | +# And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf`` |
| 40 | +RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf |
47 | 41 |
|
48 |
| -RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql |
49 |
| - |
50 |
| -ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH |
51 |
| -ENV PGDATA /var/lib/postgresql/data |
52 |
| -VOLUME /var/lib/postgresql/data |
53 |
| - |
54 |
| -COPY docker-entrypoint.sh / |
| 42 | +# Expose the PostgreSQL port |
| 43 | +EXPOSE 5432 |
55 | 44 |
|
56 |
| -ENTRYPOINT ["/docker-entrypoint.sh"] |
| 45 | +# Add VOLUMEs to allow backup of config, logs and databases |
| 46 | +#VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"] |
57 | 47 |
|
58 |
| -EXPOSE 5432 |
59 |
| -CMD ["postgres"] |
| 48 | +# Set the default command to run when starting the container |
| 49 | +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"] |
0 commit comments