postgres.dockerfile 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. FROM buildpack-deps:bionic
  2. ADD postgresql.conf postgresql.conf
  3. ADD pg_hba.conf pg_hba.conf
  4. ADD 60-postgresql-shm.conf 60-postgresql-shm.conf
  5. ADD create-postgres-database.sql create-postgres-database.sql
  6. ADD create-postgres.sql create-postgres.sql
  7. ADD pgdg.list pgdg.list
  8. # prepare PostgreSQL APT repository
  9. RUN cp pgdg.list /etc/apt/sources.list.d/
  10. RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
  11. RUN apt-get -yqq update > /dev/null
  12. RUN apt-get -yqq install locales
  13. ENV PG_VERSION 12
  14. RUN locale-gen en_US.UTF-8
  15. ENV LANG en_US.UTF-8
  16. ENV LANGUAGE en_US:en
  17. ENV LC_ALL en_US.UTF-8
  18. ENV DEBIAN_FRONTEND noninteractive
  19. # install postgresql on database machine
  20. RUN apt-get -yqq install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" postgresql postgresql-contrib
  21. # Make sure all the configuration files in main belong to postgres
  22. RUN mv postgresql.conf /etc/postgresql/${PG_VERSION}/main/postgresql.conf
  23. RUN mv pg_hba.conf /etc/postgresql/${PG_VERSION}/main/pg_hba.conf
  24. RUN chown -Rf postgres:postgres /etc/postgresql/${PG_VERSION}/main
  25. RUN mkdir /ssd
  26. RUN cp -R -p /var/lib/postgresql/${PG_VERSION}/main /ssd/postgresql
  27. RUN cp /etc/postgresql/${PG_VERSION}/main/postgresql.conf /ssd/postgresql
  28. RUN mv 60-postgresql-shm.conf /etc/sysctl.d/60-postgresql-shm.conf
  29. RUN chown -Rf postgres:postgres /var/run/postgresql
  30. RUN chmod 2777 /var/run/postgresql
  31. RUN chown postgres:postgres /etc/sysctl.d/60-postgresql-shm.conf
  32. RUN chown postgres:postgres create-postgres*
  33. RUN chown -Rf postgres:postgres /ssd
  34. ENV PGDATA=/ssd/postgresql
  35. USER postgres
  36. # We have to wait for postgres to start before we can use the cli
  37. RUN service postgresql start && \
  38. until psql -c "\q"; do sleep 1; done && \
  39. psql < create-postgres-database.sql && \
  40. psql -a hello_world < create-postgres.sql && \
  41. service postgresql stop
  42. ENV PATH $PATH:/usr/lib/postgresql/$PG_VERSION/bin
  43. CMD ["postgres"]