- Data Dockerfile to keep postgres config as well as data
- Postgres Dockerfile to make sure the data is restored even if the postgres container is removed
- Doc
This commit is contained in:
Clément MOUCHET 2014-11-30 18:19:04 +00:00
parent 39467745f1
commit 061c916fa0
4 changed files with 27 additions and 18 deletions

View File

@ -15,6 +15,8 @@ Docker containers included:
- Postgres (Postgres 9.3 and PostGIS 2.1, CKAN datastore & spatial extension supported) - Postgres (Postgres 9.3 and PostGIS 2.1, CKAN datastore & spatial extension supported)
- Solr (4.10.1, custom schemas & spatial extension supported) - Solr (4.10.1, custom schemas & spatial extension supported)
- Fig _[optional]_ (to manage the containers) - Fig _[optional]_ (to manage the containers)
- Data _[optional]_ (to store Postgres data & CKAN FileStore seperately)
Other contrib containers: Other contrib containers:
@ -45,7 +47,6 @@ Other contrib containers:
│   ├── ckan │   ├── ckan
│   ├── cron.d │   ├── cron.d
│   ├── my_init.d │   ├── my_init.d
│   ├── nginx
│   ├── postfix │   ├── postfix
│   └── supervisor │   └── supervisor
├── _service-provider (any service provider such as datapusher) ├── _service-provider (any service provider such as datapusher)
@ -57,7 +58,9 @@ Other contrib containers:
│   └── ckanext-... │   └── ckanext-...
├── docker ├── docker
│   ├── ckan │   ├── ckan
│   ├── data
│   ├── fig │   ├── fig
│   ├── nginx
│   ├── insecure_key (baseimage insecure SSH key) │   ├── insecure_key (baseimage insecure SSH key)
│   ├── postgres │   ├── postgres
│   └── solr │   └── solr
@ -110,6 +113,9 @@ The app container runs the following services
The database container runs Postgres 9.3 and PostGIS 2.1. The database container runs Postgres 9.3 and PostGIS 2.1.
It supports the [datastore](http://docs.ckan.org/en/latest/maintaining/datastore.html) & [ckanext-spatial](https://github.com/ckan/ckanext-spatial) It supports the [datastore](http://docs.ckan.org/en/latest/maintaining/datastore.html) & [ckanext-spatial](https://github.com/ckan/ckanext-spatial)
##### Data Dockerfile
The data container is optional but recommended. It exposes two volumes to store the Postgres data `($PGDATA)` & CKAN FileStore. This means you can recreate / app containers without loosing your data.
##### Solr Dockerfile ##### Solr Dockerfile
The Solr container runs version 4.10.1. This can easily be changed by customising SOLR_VERSION in the Dockerfile. The Solr container runs version 4.10.1. This can easily be changed by customising SOLR_VERSION in the Dockerfile.

View File

@ -6,14 +6,16 @@ RUN locale-gen en_US.UTF-8 && \
echo 'LANG="en_US.UTF-8"' > /etc/default/locale echo 'LANG="en_US.UTF-8"' > /etc/default/locale
ENV CKAN_DATA /var/lib/ckan ENV CKAN_DATA /var/lib/ckan
ENV PGDATA /etc/postgresql/9.3/main ENV PGDATA /var/lib/postgresql/9.3/main
ENV PGMAIN /etc/postgresql/9.3/main
RUN mkdir -p $CKAN_DATA && chown -R www-data:www-data $CKAN_DATA RUN mkdir -p $CKAN_DATA && chown -R www-data:www-data $CKAN_DATA
RUN echo "postgres:x:107:" >> /etc/group RUN echo "postgres:x:107:" >> /etc/group
RUN echo "postgres:x:103:107:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash" >> /etc/passwd RUN echo "postgres:x:103:107:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash" >> /etc/passwd
RUN mkdir -p $PGDATA && chown -R postgres:postgres $PGDATA RUN mkdir -p $PGDATA && chown -R postgres:postgres $PGDATA
RUN mkdir -p $PGMAIN && chown -R postgres:postgres $PGMAIN
CMD ["/sbin/my_init"] CMD ["/sbin/my_init"]
VOLUME ["/var/lib/ckan", "/etc/postgresql/9.3/main"] VOLUME ["/var/lib/ckan", "/etc/postgresql/9.3/main", "/var/lib/postgresql/9.3/main"]

View File

@ -24,15 +24,15 @@ ENV DATASTORE_DB datastore
ENV DATASTORE_USER datastore_user ENV DATASTORE_USER datastore_user
ENV DATASTORE_PASS datastore_pass ENV DATASTORE_PASS datastore_pass
ENV PGDATA /etc/postgresql/9.3/main ENV PGDATA /var/lib/postgresql/9.3/main
ENV PGMAIN /etc/postgresql/9.3/main
RUN mkdir -p $PGDATA && chown -R postgres $PGDATA && chmod -R 700 $PGDATA RUN mkdir -p $PGDATA && chown -R postgres $PGDATA && chmod -R 700 $PGDATA
# Allow connections from anywhere with valid credentials (md5) # Allow connections from anywhere with valid credentials (md5)
RUN sed -i -e "s|^#listen_addresses =.*$|listen_addresses = '*'|" $PGDATA/postgresql.conf RUN sed -i -e "s|^#listen_addresses =.*$|listen_addresses = '*'|" $PGMAIN/postgresql.conf
RUN echo "host all all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf RUN echo "host all all 0.0.0.0/0 md5" >> $PGMAIN/pg_hba.conf
# Configure runit # Configure runit
RUN touch /configure_db
ADD ./svc /etc/service/ ADD ./svc /etc/service/
CMD ["/sbin/my_init"] CMD ["/sbin/my_init"]

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
set -eu set -eu
if [[ -e /configure_db ]]; then if [[ ! -e "$PGDATA/db_configured" ]]; then
init_db () { init_db () {
echo "Configuring CKAN database, PostGIS & datastore" echo "Configuring CKAN database, PostGIS & datastore"
@ -59,7 +59,7 @@ if [[ -e /configure_db ]]; then
GRANT SELECT ON TABLES TO $DATASTORE_USER; GRANT SELECT ON TABLES TO $DATASTORE_USER;
EOF EOF
# Database configured # Database configured
rm /configure_db touch $PGDATA/db_configured
} }
else else
init_db () { init_db () {
@ -91,20 +91,21 @@ if [[ ! "$(ls -A $PGDATA)" ]]; then
echo "Initializing PostgreSQL..." echo "Initializing PostgreSQL..."
chown -R postgres $PGDATA chown -R postgres $PGDATA
# postgres initdb # postgres initdb
setuser postgres /usr/lib/postgresql/9.3/bin/initdb --locale=en_US.UTF-8 --encoding=UNICODE $PGDATA/ setuser postgres /usr/lib/postgresql/9.3/bin/initdb --locale=en_US.UTF-8 --encoding=UNICODE $PGDATA
mv $PGDATA/*.conf $PGMAIN/
# Update postgresql.conf settings # Update postgresql.conf settings
sed -i -e "s|^#listen_addresses =.*$|listen_addresses = '*'|" $PGDATA/postgresql.conf sed -i -e "s|^#listen_addresses =.*$|listen_addresses = '*'|" $PGMAIN/postgresql.conf
sed -i -e "s|^#data_directory =.*$|data_directory = '/var/lib/postgresql/9.3/main'|" $PGDATA/postgresql.conf sed -i -e "s|^#data_directory =.*$|data_directory = '/var/lib/postgresql/9.3/main'|" $PGMAIN/postgresql.conf
sed -i -e "s|^#hba_file =.*$|hba_file = '/etc/postgresql/9.3/main/pg_hba.conf'|" $PGDATA/postgresql.conf sed -i -e "s|^#hba_file =.*$|hba_file = '/etc/postgresql/9.3/main/pg_hba.conf'|" $PGMAIN/postgresql.conf
sed -i -e "s|^#ident_file =.*$|ident_file = '/etc/postgresql/9.3/main/pg_ident.conf'|" $PGDATA/postgresql.conf sed -i -e "s|^#ident_file =.*$|ident_file = '/etc/postgresql/9.3/main/pg_ident.conf'|" $PGMAIN/postgresql.conf
sed -i -e "s|^#external_pid_file =.*$|external_pid_file = '/var/run/postgresql/9.3-main.pid'|" $PGDATA/postgresql.conf sed -i -e "s|^#external_pid_file =.*$|external_pid_file = '/var/run/postgresql/9.3-main.pid'|" $PGMAIN/postgresql.conf
# Allow connections from anywhere with valid credentials (md5) # Allow connections from anywhere with valid credentials (md5)
echo "local all postgres peer" >> $PGDATA/pg_hba.conf echo "local all postgres peer" >> $PGMAIN/pg_hba.conf
echo "host all all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf echo "host all all 0.0.0.0/0 md5" >> $PGMAIN/pg_hba.conf
fi fi
init_db_when_ready & init_db_when_ready &
# Start PostgreSQL # Start PostgreSQL
echo "Starting PostgreSQL..." echo "Starting PostgreSQL..."
setuser postgres /usr/lib/postgresql/9.3/bin/postgres -D $PGDATA setuser postgres /usr/lib/postgresql/9.3/bin/postgres -D $PGDATA -c config_file=$PGMAIN/postgresql.conf