annotate docker/Dockerfile.db @ 9734:95496d21b4da 3.2.x

Add MapServer to Docker setup
author Tom Gottfried <tom@intevation.de>
date Fri, 22 Jul 2022 17:56:11 +0200
parents 13e2d38ad314
children 0c4736d5dd4a
rev   line source
9734
95496d21b4da Add MapServer to Docker setup
Tom Gottfried <tom@intevation.de>
parents: 9720
diff changeset
1 # Dockerfile providing a PostgreSQL database with example data for D4E River
9720
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
2 FROM debian:bullseye
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
3 LABEL maintainer tom.gottfried@intevation.de
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
4
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
5 ENV PG_VERSION 13
8795
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
6
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
7 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
8 # Use utf-8
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
9 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
10 RUN echo \
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
11 "locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8" | \
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
12 debconf-set-selections && \
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
13 echo "locales locales/default_environment_locale select en_US.UTF-8" | \
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
14 debconf-set-selections
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
15
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
16 RUN apt-get update -y && apt-get install -y locales
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
17
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
18 ENV LC_ALL en_US.UTF-8
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
19
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
20 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
21 # Install packages
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
22 #
9720
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
23 RUN apt-get install -y postgresql-$PG_VERSION-postgis-3 curl
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
24 RUN apt-get -y clean
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
25
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
26 ENV PGCONF /etc/postgresql/$PG_VERSION/main/postgresql.conf
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
27 ENV PGBIN /usr/lib/postgresql/$PG_VERSION/bin/
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
28 ENV PGDATA /var/lib/postgresql/$PG_VERSION/main
8795
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
29
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
30 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
31 # Use user postgres to run the next commands
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
32 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
33 USER postgres
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
34
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
35 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
36 # Adjust PostgreSQL configuration so that remote connections to the
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
37 # database are possible.
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
38 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
39 RUN echo "host all all 0.0.0.0/0 md5" >> \
9720
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
40 /etc/postgresql/$PG_VERSION/main/pg_hba.conf
8795
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
41
8817
8927ec8a3c32 Add demodata and fix server startup in DB Dockerfile.
Tom Gottfried <tom@intevation.de>
parents: 8795
diff changeset
42 RUN echo "listen_addresses='*'" >> $PGCONF
8795
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
43
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
44 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
45 # Expose the PostgreSQL port
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
46 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
47 EXPOSE 5432
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
48
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
49 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
50 # Create database
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
51 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
52 # Don't mind scary messages like
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
53 # 'FATAL: the database system is starting up'.
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
54 # It's because of the -w
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
55 #
9684
537fe44f2792 Add basic Docker setup for development
Tom Gottfried <tom@intevation.de>
parents: 8817
diff changeset
56 ADD ./backend/doc/schema /opt/d4eriver_db
8795
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
57
8817
8927ec8a3c32 Add demodata and fix server startup in DB Dockerfile.
Tom Gottfried <tom@intevation.de>
parents: 8795
diff changeset
58 # Go to postgres home for write permissions
8927ec8a3c32 Add demodata and fix server startup in DB Dockerfile.
Tom Gottfried <tom@intevation.de>
parents: 8795
diff changeset
59 ENV DATA_ARCH demodaten_3.1.10-bis-3.2.x.tar.gz
9720
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
60 RUN curl -sf "https://wald.intevation.org/frs/download.php/2282/$DATA_ARCH" | \
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
61 tar -C $HOME --wildcards -xz 'demodaten/*.dump.sql'
8817
8927ec8a3c32 Add demodata and fix server startup in DB Dockerfile.
Tom Gottfried <tom@intevation.de>
parents: 8795
diff changeset
62
9734
95496d21b4da Add MapServer to Docker setup
Tom Gottfried <tom@intevation.de>
parents: 9720
diff changeset
63 # Initialize database
95496d21b4da Add MapServer to Docker setup
Tom Gottfried <tom@intevation.de>
parents: 9720
diff changeset
64 # Note that PostGIS legacy.sql is needed to support the outdated MapServer 6
9720
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
65 RUN $PGBIN/pg_ctl start -wo "--config_file=$PGCONF" && \
8817
8927ec8a3c32 Add demodata and fix server startup in DB Dockerfile.
Tom Gottfried <tom@intevation.de>
parents: 8795
diff changeset
66 /opt/d4eriver_db/postgresql-setup.sh && \
9720
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
67 psql -f ~/demodaten/d4e_demodata.dump.sql d4e && \
9734
95496d21b4da Add MapServer to Docker setup
Tom Gottfried <tom@intevation.de>
parents: 9720
diff changeset
68 psql -d d4e -f /usr/share/postgresql/$PG_VERSION/contrib/postgis-3.1/legacy.sql && \
8817
8927ec8a3c32 Add demodata and fix server startup in DB Dockerfile.
Tom Gottfried <tom@intevation.de>
parents: 8795
diff changeset
69 createuser -S -D -R seddb && \
9684
537fe44f2792 Add basic Docker setup for development
Tom Gottfried <tom@intevation.de>
parents: 8817
diff changeset
70 psql -c "ALTER USER seddb WITH PASSWORD 'seddb'" && \
8817
8927ec8a3c32 Add demodata and fix server startup in DB Dockerfile.
Tom Gottfried <tom@intevation.de>
parents: 8795
diff changeset
71 createdb seddb && \
9720
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
72 psql -f ~/demodaten/seddb_demodata.dump.sql seddb && \
9684
537fe44f2792 Add basic Docker setup for development
Tom Gottfried <tom@intevation.de>
parents: 8817
diff changeset
73 psql -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO seddb" seddb && \
9720
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
74 $PGBIN/pg_ctl stop -m smart
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
75
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
76 RUN rm -r ~/demodaten
8795
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
77
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
78 #
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
79 # Set the default command to run when starting the container
13d5b6c67cef Add Dockerfile for Postgres-DB setup.
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
80 #
9720
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
81 CMD ["/usr/lib/postgresql/13/bin/postgres", "-D", \
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
82 "/var/lib/postgresql/13/main", "-c", \
13e2d38ad314 Improve Docker based setup
Tom Gottfried <tom@intevation.de>
parents: 9716
diff changeset
83 "config_file=/etc/postgresql/13/main/postgresql.conf"]

http://dive4elements.wald.intevation.org