postgres.dockerfile 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. FROM ubuntu:16.04
  2. RUN apt-get update
  3. RUN apt-get install -qqy locales
  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. # install postgresql on database machine
  14. RUN apt-get -y update
  15. RUN apt-get -y install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" postgresql
  16. ENV PG_VERSION 9.5
  17. # Make sure all the configuration files in main belong to postgres
  18. RUN mv postgresql.conf /etc/postgresql/${PG_VERSION}/main/postgresql.conf
  19. RUN mv pg_hba.conf /etc/postgresql/${PG_VERSION}/main/pg_hba.conf
  20. RUN chown -Rf postgres:postgres /etc/postgresql/${PG_VERSION}/main
  21. RUN mkdir /ssd
  22. RUN cp -R -p /var/lib/postgresql/${PG_VERSION}/main /ssd/postgresql
  23. RUN cp /etc/postgresql/${PG_VERSION}/main/postgresql.conf /ssd/postgresql
  24. RUN mv 60-postgresql-shm.conf /etc/sysctl.d/60-postgresql-shm.conf
  25. RUN chown -Rf postgres:postgres /var/run/postgresql
  26. RUN chmod 2777 /var/run/postgresql
  27. RUN chown postgres:postgres /etc/sysctl.d/60-postgresql-shm.conf
  28. RUN chown postgres:postgres create-postgres*
  29. RUN chown -Rf postgres:postgres /ssd
  30. USER postgres
  31. # We have to wait for postgres to start before we can use the cli
  32. RUN service postgresql start && \
  33. until psql -c "\q"; do sleep 1; done && \
  34. psql < create-postgres-database.sql && \
  35. psql -q hello_world < create-postgres.sql
  36. EXPOSE 5432
  37. ENV PATH $PATH:/usr/lib/postgresql/$PG_VERSION/bin
  38. ENV PGDATA=/var/lib/postgresql/data
  39. CMD ["postgres", "-D", "/ssd/postgresql"]