postgres.dockerfile 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. FROM ubuntu:16.04
  2. RUN apt-get update > /dev/null
  3. RUN apt-get install -yqq locales > /dev/null
  4. RUN locale-gen en_US.UTF-8
  5. ENV LANG en_US.UTF-8
  6. ENV LANGUAGE en_US:en
  7. ENV LC_ALL en_US.UTF-8
  8. ADD postgresql.conf postgresql.conf
  9. ADD pg_hba.conf pg_hba.conf
  10. ADD 60-postgresql-shm.conf 60-postgresql-shm.conf
  11. ADD create-postgres-database.sql create-postgres-database.sql
  12. ADD create-postgres.sql create-postgres.sql
  13. ADD pgdg.list pgdg.list
  14. # prepare PostgreSQL APT repository
  15. RUN cp pgdg.list /etc/apt/sources.list.d/
  16. RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ACCC4CF8
  17. # install postgresql on database machine
  18. RUN apt-get -y update > /dev/null
  19. RUN apt-get -y install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" postgresql > /dev/null
  20. ENV PG_VERSION 11
  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"]