Created
March 6, 2019 23:41
-
-
Save peacefixation/75aa2d0a8a02c0c8287ae29f32484784 to your computer and use it in GitHub Desktop.
Debian Postgresql container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM debian:stretch | |
LABEL maintainer="First Last <[email protected]>" | |
ARG POSTGRES_VER=9.6 | |
ARG TZ=Australia/Melbourne | |
ARG DEBIAN_FRONTEND=noninteractive | |
# Ensure Timezone is correct | |
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone | |
# Ensure APT repo is up to date | |
RUN apt-get update | |
# Install Postgresql | |
RUN apt-get -y install postgresql-${POSTGRES_VER} | |
RUN echo "" >> /etc/postgresql/${POSTGRES_VER}/main/postgresql.conf | |
RUN echo "listen_addresses = '\*'" >> /etc/postgresql/${POSTGRES_VER}/main/postgresql.conf | |
RUN echo "timezone = 'localtime'" >> /etc/postgresql/${POSTGRES_VER}/main/postgresql.conf | |
RUN echo "log_timezone = 'localtime'" >> /etc/postgresql/${POSTGRES_VER}/main/postgresql.conf | |
RUN echo "log_min_duration_statement = 0" >> /etc/postgresql/${POSTGRES_VER}/main/postgresql.conf | |
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/${POSTGRES_VER}/main/pg_hba.conf | |
RUN ln -s /var/log/postgresql/postgresql-${POSTGRES_VER}-main.log /var/log/postgres.log | |
# dump.sql is the output from pg_dumpall on an existing database | |
ADD dump.sql /dump.sql | |
RUN chmod -v 666 /dump.sql | |
RUN service postgresql start; \ | |
su - postgres -c "psql -f /dump.sql"; \ | |
su - postgres -c "psql -c \"ALTER USER postgres with password 'postgres';\""; \ | |
service postgresql stop | |
RUN rm /dump.sql | |
# Cleanup to reduce image size | |
RUN apt-get clean | |
# Add startup script | |
# #!/bin/bash | |
# service postgresql start | |
# tail -F /var/log/postgres.log | |
ADD run.sh /run.sh | |
RUN chmod -v +x /run.sh | |
# Expose Postgres port | |
EXPOSE 5432 | |
# What to execute | |
CMD ["/run.sh"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment