postgres.dockerfile 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. FROM ubuntu:16.04
  2. RUN apt update
  3. RUN apt install -yqq 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 -y update
  15. RUN apt -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. ENV PGDATA=/ssd/postgresql
  31. USER postgres
  32. # We have to wait for postgres to start before we can use the cli
  33. RUN service postgresql start && \
  34. until psql -c "\q"; do sleep 1; done && \
  35. psql < create-postgres-database.sql && \
  36. psql -a hello_world < create-postgres.sql && \
  37. service postgresql stop
  38. ENV PATH $PATH:/usr/lib/postgresql/$PG_VERSION/bin
  39. CMD ["postgres"]