postgres.dockerfile 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 14
  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-${PG_VERSION} postgresql-contrib-${PG_VERSION}
  21. # Make sure all the configuration files in main belong to postgres
  22. RUN sed -i "s|PG_VERSION|${PG_VERSION}|g" postgresql.conf
  23. RUN mv postgresql.conf /etc/postgresql/${PG_VERSION}/main/postgresql.conf
  24. RUN mv pg_hba.conf /etc/postgresql/${PG_VERSION}/main/pg_hba.conf
  25. RUN chown -Rf postgres:postgres /etc/postgresql/${PG_VERSION}/main
  26. RUN mkdir /ssd
  27. RUN cp -R -p /var/lib/postgresql/${PG_VERSION}/main /ssd/postgresql
  28. RUN cp /etc/postgresql/${PG_VERSION}/main/postgresql.conf /ssd/postgresql
  29. RUN mv 60-postgresql-shm.conf /etc/sysctl.d/60-postgresql-shm.conf
  30. RUN chown -Rf postgres:postgres /var/run/postgresql
  31. RUN chmod 2777 /var/run/postgresql
  32. RUN chown postgres:postgres /etc/sysctl.d/60-postgresql-shm.conf
  33. RUN chown postgres:postgres create-postgres*
  34. RUN chown -Rf postgres:postgres /ssd
  35. ENV PGDATA=/ssd/postgresql
  36. USER postgres
  37. # We have to wait for postgres to start before we can use the cli
  38. RUN service postgresql start && \
  39. until psql -c "\q"; do sleep 1; done && \
  40. psql < create-postgres-database.sql && \
  41. psql -a hello_world < create-postgres.sql && \
  42. service postgresql stop
  43. ENV PATH $PATH:/usr/lib/postgresql/$PG_VERSION/bin
  44. CMD ["postgres"]