tom@1161: # Docker file for the LADA database on Debian tom@743: # tom@743: # build with e.g. `docker build --force-rm=true -t koala/lada_db .', tom@743: # then run with e.g. tom@743: # `docker run --name lada_db -dp 2345:5432 koala/lada_db:latest' tom@743: # tom@1086: # For easier testing of schema or example data changes, it can be useful to add tom@1086: # `-v $PWD:/opt/lada_sql/' and run setup-db.sh within the container. tom@1086: # tom@743: tom@743: FROM debian:jessie tom@743: MAINTAINER tom.gottfried@intevation.de tom@743: tom@743: # tom@743: # Use utf-8 tom@743: # tom@743: RUN echo \ tom@743: "locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8" | \ tom@743: debconf-set-selections && \ tom@743: echo "locales locales/default_environment_locale select en_US.UTF-8" | \ tom@743: debconf-set-selections tom@743: tom@743: RUN apt-get update -y && apt-get install -y locales tom@743: tom@743: ENV LC_ALL en_US.UTF-8 tom@743: tom@743: # tom@743: # Install packages tom@743: # tom@743: RUN apt-get update && \ tom@1161: apt-get install -y curl unzip make gcc tom@1161: RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main" \ tom@1161: >> /etc/apt/sources.list tom@1161: RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - tom@1161: RUN apt-get update && \ tom@1161: apt-get install -y --no-install-recommends \ tom@1161: postgresql-9.5-postgis-2.3 postgresql-9.5-postgis-scripts postgis \ tom@1161: postgresql-server-dev-9.5 \ tom@1161: libdbi-perl libdbd-pg-perl # for pgaudit/analyze tom@1161: tom@1161: # tom@1161: # Add context as working directory tom@1161: # tom@1161: ADD . /opt/lada_sql/ tom@1161: WORKDIR /opt/lada_sql/ tom@1161: tom@1161: # tom@1161: # Set environment variables tom@1161: # tom@1161: ENV PGCONF /etc/postgresql/9.5/main/postgresql.conf tom@1161: ENV PGDATA /var/lib/postgresql/9.5/main tom@1161: tom@1161: # tom@1161: # Install pgaudit tom@1161: # tom@1161: # run `git clone https://github.com/pgaudit/pgaudit.git' within context tom@1161: # before building image! tom@1161: RUN sed -i '/^USE_PGXS/b;1iUSE_PGXS = yes' pgaudit/Makefile tom@1161: RUN cd pgaudit && make install tom@1161: RUN echo "shared_preload_libraries = 'pgaudit'" >> $PGCONF tom@743: tom@743: # tom@743: # Use user postgres to run the next commands tom@743: # tom@743: USER postgres tom@743: tom@1162: # XXX: Seems to fail on initdb issued by package installation tom@1162: # (due to /usr/sbin/policy-rc.d ?). tom@1162: # See also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=739276 tom@1162: RUN mkdir /var/run/postgresql/9.5-main.pg_stat_tmp tom@743: tom@743: # tom@743: # Adjust PostgreSQL configuration so that remote connections to the tom@743: # database are possible. tom@743: # tom@743: RUN echo "host all all 0.0.0.0/0 md5" >> \ tom@1161: /etc/postgresql/9.5/main/pg_hba.conf tom@1161: RUN echo "listen_addresses='*'" >> $PGCONF tom@743: tom@1161: # tom@1161: # Configure logging collector tom@1161: # (because we use postgres directly in CMD, tom@1161: # the usual collection from stderr does not work) tom@1161: # tom@1161: RUN echo "logging_collector = on" >> $PGCONF tom@1161: RUN echo "log_directory = '/var/log/postgresql'" >> $PGCONF tom@1161: #RUN echo "log_filename = 'postgresql-9.5-main.log'" >> $PGCONF tom@1161: # for pgaudit/analyze tom@1161: RUN echo "log_filename = '%F'" >> $PGCONF tom@1161: RUN echo "log_destination = 'csvlog'" >> $PGCONF tom@1161: RUN echo "log_connections = on" >> $PGCONF tom@743: tom@743: # tom@743: # Expose the PostgreSQL port tom@743: # tom@743: EXPOSE 5432 tom@743: tom@743: # tom@743: # Create database tom@743: # tom@743: # Don't mind scary messages like tom@743: # 'FATAL: the database system is starting up'. tom@743: # It's because of the -w tom@743: # tom@1161: RUN /usr/lib/postgresql/9.5/bin/pg_ctl start -wo "--config_file=$PGCONF" && \ tom@1161: /opt/lada_sql/setup-db.sh && \ tom@1161: /usr/lib/postgresql/9.5/bin/pg_ctl stop tom@743: tom@743: # tom@743: # Set the default command to run when starting the container tom@743: # tom@1161: CMD ["/usr/lib/postgresql/9.5/bin/postgres", \ tom@1161: "--config_file=/etc/postgresql/9.5/main/postgresql.conf"] tom@1161: tom@1161: # To use pgaudit/analyze from within the container: tom@1161: # cd pgaudit/analyze/bin tom@1161: # ./pgaudit_analyze /var/log/postgresql/ \ tom@1161: # --log-file /var/log/postgresql/pgaudit_analyze.log