Dockerfile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # vim:set ft=dockerfile:
  2. FROM debian:jessie
  3. # explicitly set user/group IDs
  4. RUN groupadd -r postgres --gid=999 && useradd -r -g postgres --uid=999 postgres
  5. # grab gosu for easy step-down from root
  6. ENV GOSU_VERSION 1.7
  7. RUN set -x \
  8. && apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
  9. && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
  10. && wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
  11. && export GNUPGHOME="$(mktemp -d)" \
  12. && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
  13. && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
  14. && rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
  15. && chmod +x /usr/local/bin/gosu \
  16. && gosu nobody true \
  17. && apt-get purge -y --auto-remove ca-certificates wget
  18. # make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
  19. RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \
  20. && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
  21. ENV LANG en_US.utf8
  22. RUN mkdir /docker-entrypoint-initdb.d
  23. RUN set -ex; \
  24. # pub 4096R/ACCC4CF8 2011-10-13 [expires: 2019-07-02]
  25. # Key fingerprint = B97B 0AFC AA1A 47F0 44F2 44A0 7FCC 7D46 ACCC 4CF8
  26. # uid PostgreSQL Debian Repository
  27. key='B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8'; \
  28. export GNUPGHOME="$(mktemp -d)"; \
  29. gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
  30. gpg --export "$key" > /etc/apt/trusted.gpg.d/postgres.gpg; \
  31. rm -r "$GNUPGHOME"; \
  32. apt-key list
  33. ENV PG_MAJOR 9.6
  34. ENV PG_VERSION 9.6.2-1.pgdg80+1
  35. RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
  36. RUN apt-get update \
  37. && apt-get install -y postgresql-common \
  38. && sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \
  39. && apt-get install -y \
  40. postgresql-$PG_MAJOR=$PG_VERSION \
  41. postgresql-contrib-$PG_MAJOR=$PG_VERSION \
  42. && rm -rf /var/lib/apt/lists/*
  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
  47. RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
  48. ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
  49. ENV PGDATA /var/lib/postgresql/data
  50. RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA" # this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
  51. VOLUME /var/lib/postgresql/data
  52. COPY docker-entrypoint.sh /usr/local/bin/
  53. RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat
  54. ENTRYPOINT ["docker-entrypoint.sh"]
  55. EXPOSE 5432
  56. CMD ["postgres"]