docker-scripts/linux/ecosystem/postgres/14/Dockerfile

97 lines
4.9 KiB
Docker
Raw Normal View History

2022-05-07 03:11:26 +03:00
FROM epicmorg/debian:bullseye
2021-08-18 23:24:17 +03:00
LABEL maintainer="EpicMorg DevTeam, developer@epicm.org"
ARG DEBIAN_FRONTEND=noninteractive
####################################################################################################################################
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
####################################################################################################################################
RUN groupadd -r postgres && useradd -r -g postgres postgres
####################################################################################################################################
# grab gosu for easy step-down from root
####################################################################################################################################
ENV GOSU_VER 1.14
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* \
2022-11-13 01:05:12 +03:00
&& wget -q --no-check-certificate -c https://github.com/tianon/gosu/releases/download/$GOSU_VER/gosu-amd64 --random-wait -O /usr/local/bin/gosu \
2021-08-18 23:24:17 +03:00
&& chmod +x /usr/local/bin/gosu \
&& apt-get purge -y --auto-remove curl
####################################################################################################################################
# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
####################################################################################################################################
RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
####################################################################################################################################
# http://apt.postgresql.org/pub/repos/apt/pool/14/p/postgresql-14/
####################################################################################################################################
ENV PG_MAJOR 14
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list && \
2022-11-13 01:40:09 +03:00
echo 'deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg-snapshot main' $PG_MAJOR >> /etc/apt/sources.list.d/pgdg.list && \
2021-08-18 23:24:17 +03:00
echo 'deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg-testing main' $PG_MAJOR >> /etc/apt/sources.list.d/pgdg.list
RUN apt-get update \
&& apt-get install -y postgresql-common \
&& sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \
&& apt-get install -y \
postgresql-$PG_MAJOR \
postgresql-contrib-$PG_MAJOR \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir /docker-entrypoint-initdb.d
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
ENV PGDATA /var/lib/postgresql/data
VOLUME /var/lib/postgresql/data
WORKDIR /var/lib/postgresql/data
2022-03-21 22:05:56 +03:00
#healthcheck. good practice
2022-03-21 22:14:03 +03:00
HEALTHCHECK --interval=3m --timeout=3s CMD pg_isready || exit 1
2021-08-18 23:24:17 +03:00
2022-03-21 22:05:56 +03:00
# Add image configuration and scripts
COPY docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
RUN chmod 755 /usr/bin/docker-entrypoint.sh
ENTRYPOINT ["tini", "-s", "--", "docker-entrypoint.sh"]
2021-08-18 23:24:17 +03:00
# We set the default STOPSIGNAL to SIGINT, which corresponds to what PostgreSQL
# calls "Fast Shutdown mode" wherein new connections are disallowed and any
# in-progress transactions are aborted, allowing PostgreSQL to stop cleanly and
# flush tables to disk, which is the best compromise available to avoid data
# corruption.
#
# Users who know their applications do not keep open long-lived idle connections
# may way to use a value of SIGTERM instead, which corresponds to "Smart
# Shutdown mode" in which any existing sessions are allowed to finish and the
# server stops when all sessions are terminated.
#
# See https://www.postgresql.org/docs/12/server-shutdown.html for more details
# about available PostgreSQL server shutdown signals.
#
# See also https://www.postgresql.org/docs/12/server-start.html for further
# justification of this as the default value, namely that the example (and
# shipped) systemd service files use the "Fast Shutdown mode" for service
# termination.
#
STOPSIGNAL SIGINT
#
# An additional setting that is recommended for all users regardless of this
# value is the runtime "--stop-timeout" (or your orchestrator/runtime's
# equivalent) for controlling how long to wait between sending the defined
# STOPSIGNAL and sending SIGKILL (which is likely to cause data corruption).
#
# The default in most runtimes (such as Docker) is 10 seconds, and the
# documentation at https://www.postgresql.org/docs/12/server-start.html notes
# that even 90 seconds may not be long enough in many instances.
EXPOSE 5432
CMD ["postgres"]