postgres.dockerfile 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. FROM ubuntu:22.04
  2. ARG PG_VERSION=15
  3. COPY 60-postgresql-shm.conf pg_hba.conf postgresql.conf ./
  4. COPY create-postgres.sql create-postgres-database.sql /tmp/
  5. # Prepare the PostgreSQL APT repository
  6. ARG DEBIAN_FRONTEND=noninteractive
  7. ADD "https://www.postgresql.org/media/keys/ACCC4CF8.asc" /etc/apt/keyrings/postgresql.asc
  8. RUN chmod 644 /etc/apt/keyrings/postgresql.asc && \
  9. apt-get -yqq update && \
  10. apt-get -yqq install \
  11. apt-utils \
  12. locales \
  13. lsb-release && \
  14. echo "deb [ signed-by=/etc/apt/keyrings/postgresql.asc ] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > \
  15. /etc/apt/sources.list.d/pgdg.list && \
  16. locale-gen en_US.UTF-8
  17. ENV LANG=en_US.UTF-8
  18. ENV LANGUAGE=en_US:en
  19. ENV LC_ALL=en_US.UTF-8
  20. # Install PostgreSQL on the database machine
  21. RUN apt-get -yqq update && \
  22. apt-get -yqq install \
  23. -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
  24. postgresql-${PG_VERSION} \
  25. postgresql-contrib-${PG_VERSION} && \
  26. sed -i "s|PG_VERSION|${PG_VERSION}|g" postgresql.conf && \
  27. mv pg_hba.conf postgresql.conf /etc/postgresql/${PG_VERSION}/main && \
  28. mkdir /ssd && \
  29. cp -Rp /var/lib/postgresql/${PG_VERSION}/main /ssd/postgresql && \
  30. cp /etc/postgresql/${PG_VERSION}/main/postgresql.conf /ssd/postgresql && \
  31. mv 60-postgresql-shm.conf /etc/sysctl.d/60-postgresql-shm.conf && \
  32. chown -Rf postgres:postgres \
  33. /etc/postgresql/${PG_VERSION}/main \
  34. /etc/sysctl.d/60-postgresql-shm.conf \
  35. /ssd \
  36. /tmp/create-postgres* \
  37. /var/run/postgresql && \
  38. chmod 2777 /var/run/postgresql
  39. ENV PGDATA=/ssd/postgresql
  40. USER postgres
  41. # We have to wait for PostgreSQL to start before we can use the CLI
  42. RUN service postgresql start && \
  43. until psql -c "\q"; do sleep 1; done && \
  44. psql < /tmp/create-postgres-database.sql && \
  45. psql -a hello_world < /tmp/create-postgres.sql && \
  46. service postgresql stop
  47. ENV PATH=${PATH}:/usr/lib/postgresql/${PG_VERSION}/bin
  48. CMD ["postgres"]