kopia lustrzana https://github.com/kartoza/docker-postgis
Merge remote-tracking branch 'upstream/develop'
commit
f85714416d
|
@ -1,6 +1,6 @@
|
||||||
#--------- Generic stuff all our Dockerfiles should start with so we get caching ------------
|
#--------- Generic stuff all our Dockerfiles should start with so we get caching ------------
|
||||||
FROM ubuntu:trusty
|
FROM ubuntu:trusty
|
||||||
MAINTAINER Tim Sutton<tim@linfiniti.com>
|
MAINTAINER Tim Sutton<tim@kartoza.com>
|
||||||
|
|
||||||
RUN export DEBIAN_FRONTEND=noninteractive
|
RUN export DEBIAN_FRONTEND=noninteractive
|
||||||
ENV DEBIAN_FRONTEND noninteractive
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
@ -38,5 +38,7 @@ RUN /setup.sh
|
||||||
ADD start-postgis.sh /start-postgis.sh
|
ADD start-postgis.sh /start-postgis.sh
|
||||||
RUN chmod 0755 /start-postgis.sh
|
RUN chmod 0755 /start-postgis.sh
|
||||||
|
|
||||||
USER postgres
|
ADD perms_wrapper.sh /perms_wrapper.sh
|
||||||
CMD /start-postgis.sh
|
RUN chmod 0755 /perms_wrapper.sh
|
||||||
|
|
||||||
|
CMD /perms_wrapper.sh
|
||||||
|
|
59
README.md
59
README.md
|
@ -18,20 +18,33 @@ environment (though probably not for heavy load databases).
|
||||||
**Note:** We recommend using ``apt-cacher-ng`` to speed up package fetching -
|
**Note:** We recommend using ``apt-cacher-ng`` to speed up package fetching -
|
||||||
you should configure the host for it in the provided 71-apt-cacher-ng file.
|
you should configure the host for it in the provided 71-apt-cacher-ng file.
|
||||||
|
|
||||||
## Build
|
## Getting the image
|
||||||
|
|
||||||
To build the image without apt-cacher do:
|
There are various ways to get the image onto your system:
|
||||||
|
|
||||||
|
|
||||||
|
The preferred way (but using most bandwidth for the initial image) is to
|
||||||
|
get our docker trusted build like this:
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
docker pull kartoza/postgis
|
||||||
|
```
|
||||||
|
|
||||||
|
To build the image yourself without apt-cacher (also consumes more bandwidth
|
||||||
|
since deb packages need to be refetched each time you build) do:
|
||||||
|
|
||||||
```
|
```
|
||||||
docker build -t kartoza/postgis git://github.com/kartoza/docker-postgis
|
docker build -t kartoza/postgis git://github.com/kartoza/docker-postgis
|
||||||
```
|
```
|
||||||
|
|
||||||
To build with apt-cache do you need to clone this repo locally first and
|
To build with apt-cache (and minimised download requirements) do you need to
|
||||||
modify the contents of 71-apt-cacher-ng to match your cacher host. Then
|
clone this repo locally first and modify the contents of 71-apt-cacher-ng to
|
||||||
build using a local url instead of directly from github.
|
match your cacher host. Then build using a local url instead of directly from
|
||||||
|
github.
|
||||||
|
|
||||||
```
|
```
|
||||||
git clone git://github.com/timlinux/docker-postgis
|
git clone git://github.com/kartoza/docker-postgis
|
||||||
```
|
```
|
||||||
|
|
||||||
Now edit ``71-apt-cacher-ng`` then do:
|
Now edit ``71-apt-cacher-ng`` then do:
|
||||||
|
@ -49,9 +62,39 @@ To create a running container do:
|
||||||
sudo docker run --name "postgis" -p 25432:5432 -d -t kartoza/postgis
|
sudo docker run --name "postgis" -p 25432:5432 -d -t kartoza/postgis
|
||||||
```
|
```
|
||||||
|
|
||||||
## Connect via psql
|
You can also use the following environment variables to pass a
|
||||||
|
user name and password.
|
||||||
|
|
||||||
To log in to your container do:
|
* -e USERNAME=<PGUSER>
|
||||||
|
* -e PASS=<PGPASSWORD>
|
||||||
|
|
||||||
|
These will be used to create a new superuser with
|
||||||
|
your preferred credentials. If these are not specified then the postgresql
|
||||||
|
user is set to 'docker' with password 'docker'.
|
||||||
|
|
||||||
|
## Convenience run script
|
||||||
|
|
||||||
|
For convenience we have provided a bash script for running this container
|
||||||
|
that lets you specify a volume mount point and a username / password
|
||||||
|
for the new instance superuser. It takes these options:
|
||||||
|
|
||||||
|
```
|
||||||
|
OPTIONS:
|
||||||
|
-h Show this message
|
||||||
|
-n Container name
|
||||||
|
-v Volume to mount the Postgres cluster into
|
||||||
|
-u Postgres user name (defaults to 'docker')
|
||||||
|
-p Postgres password (defaults to 'docker')
|
||||||
|
```
|
||||||
|
|
||||||
|
Example usage:
|
||||||
|
|
||||||
|
```
|
||||||
|
./run-postgis-docker.sh -v /tmp/foo/ -n postgis -u foo -p bar
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Connect via psql
|
||||||
|
|
||||||
Connect with psql (make sure you first install postgresql client tools on your
|
Connect with psql (make sure you first install postgresql client tools on your
|
||||||
host / client):
|
host / client):
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# needs to be done as root:
|
||||||
|
chown -R postgres:postgres /var/lib/postgresql
|
||||||
|
|
||||||
|
# everything else needs to be done as non-root (i.e. postgres)
|
||||||
|
sudo -u postgres /start-postgis.sh
|
|
@ -1,43 +1,83 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Commit and redeploy the user map container
|
# Commit and redeploy the user map container
|
||||||
|
|
||||||
# Note this script hosts the postgis cluster on the host filesystem
|
usage()
|
||||||
# If you want to use the container with the cluster embedded
|
{
|
||||||
# In the container, run it like this:
|
cat << EOF
|
||||||
|
usage: $0 options
|
||||||
|
|
||||||
|
This script runs a new docker postgis instance for you.
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
-h Show this message
|
||||||
|
-n Container name
|
||||||
|
-v Volume to mount the Postgres cluster into
|
||||||
|
-u Postgres user name (defaults to 'docker')
|
||||||
|
-p Postgres password (defaults to 'docker')
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts ":h:n:v:u:p:" OPTION
|
||||||
|
do
|
||||||
|
case $OPTION in
|
||||||
|
n)
|
||||||
|
CONTAINER_NAME=${OPTARG}
|
||||||
|
;;
|
||||||
|
v)
|
||||||
|
VOLUME=${OPTARG}
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
PGUSER=${OPTARG}
|
||||||
|
;;
|
||||||
|
p)
|
||||||
|
PGPASSWORD=${OPTARG}
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
#
|
if [[ -z $VOLUME ]] || [[ -z $CONTAINER_NAME ]] || [[ -z $PGUSER ]] || [[ -z $PGPASSWORD ]]
|
||||||
if [ $# -ne 1 ]; then
|
then
|
||||||
echo "Deploy the postgis container."
|
usage
|
||||||
echo "Usage:"
|
|
||||||
echo "$0 <version>"
|
|
||||||
echo "e.g.:"
|
|
||||||
echo "$0 2.1"
|
|
||||||
echo "Will run the container using tag version 2.1"
|
|
||||||
echo "Once it is running see the commit-and-deploy.sh script if you"
|
|
||||||
echo "wish to save new snapshots."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
VERSION=$1
|
|
||||||
HOST_DATA_DIR=/var/docker-data/postgres-dat
|
|
||||||
PGUSER=qgis
|
|
||||||
PGPASS=qgis
|
|
||||||
|
|
||||||
IDFILE=/home/timlinux/postgis-current-container.id
|
if [[ ! -z $VOLUME ]]
|
||||||
|
then
|
||||||
|
VOLUME_OPTION="-v ${VOLUME}:/var/lib/postgresql"
|
||||||
|
else
|
||||||
|
VOLUME_OPTION=""
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -d $HOST_DATA_DIR ]
|
if [ ! -d $HOST_DATA_DIR ]
|
||||||
then
|
then
|
||||||
mkdir $HOST_DATA_DIR
|
mkdir $HOST_DATA_DIR
|
||||||
fi
|
fi
|
||||||
CMD="docker run -cidfile="$IDFILE" -name="postgis" -e USERNAME=$PGUSER -e PASS=$PGPASS -d -v $HOST_DATA_DIR:/var/lib/postgresql -t qgis/postgis:$VERSION /start.sh"
|
chmod a+w $HOST_DATA_DIR
|
||||||
echo 'Running:'
|
|
||||||
|
docker kill ${CONTAINER_NAME}
|
||||||
|
docker rm ${CONTAINER_NAME}
|
||||||
|
|
||||||
|
CMD="docker run --name="${CONTAINER_NAME}" \
|
||||||
|
--hostname="${CONTAINER_NAME}" \
|
||||||
|
--restart=always \
|
||||||
|
-e USERNAME=${PGUSER} \
|
||||||
|
-e PASS=${PGPASSWORD} \
|
||||||
|
-d -t \
|
||||||
|
${VOLUME_OPTION} \
|
||||||
|
kartoza/postgis /start-postgis.sh"
|
||||||
|
|
||||||
|
echo 'Running\n'
|
||||||
echo $CMD
|
echo $CMD
|
||||||
eval $CMD
|
eval $CMD
|
||||||
NEWID=`cat $IDFILE`
|
|
||||||
echo "Postgis has been deployed as $NEWID"
|
docker ps | grep ${CONTAINER_NAME}
|
||||||
docker ps -a | grep $NEWID
|
|
||||||
echo "If there was no pre-existing database, you can access this using"
|
echo "Connect using:"
|
||||||
IPADDRESS=`docker inspect postgis | grep IPAddress | grep -o '[0-9\.]*'`
|
|
||||||
echo "psql -l -p 5432 -h $IPADDRESS -U $PGUSER"
|
echo "psql -l -p 5432 -h $IPADDRESS -U $PGUSER"
|
||||||
echo "and password $PGPASS"
|
echo "and password $PGPASS"
|
||||||
echo
|
echo
|
||||||
|
|
11
setup.sh
11
setup.sh
|
@ -5,12 +5,11 @@ CONF="/etc/postgresql/9.3/main/postgresql.conf"
|
||||||
|
|
||||||
# /etc/ssl/private can't be accessed from within container for some reason
|
# /etc/ssl/private can't be accessed from within container for some reason
|
||||||
# (@andrewgodwin says it's something AUFS related) - taken from https://github.com/orchardup/docker-postgresql/blob/master/Dockerfile
|
# (@andrewgodwin says it's something AUFS related) - taken from https://github.com/orchardup/docker-postgresql/blob/master/Dockerfile
|
||||||
mkdir -p /etc/ssl/private-copy
|
cp -r /etc/ssl /tmp/ssl-copy/
|
||||||
mv /etc/ssl/private/* /etc/ssl/private-copy/
|
chmod -R 0700 /etc/ssl
|
||||||
rm -r /etc/ssl/private
|
chown -R postgres /tmp/ssl-copy
|
||||||
mv /etc/ssl/private-copy /etc/ssl/private
|
rm -r /etc/ssl
|
||||||
chmod -R 0700 /etc/ssl/private
|
mv /tmp/ssl-copy /etc/ssl
|
||||||
chown -R postgres /etc/ssl/private
|
|
||||||
|
|
||||||
# Restrict subnet to docker private network
|
# Restrict subnet to docker private network
|
||||||
echo "host all all 172.17.0.0/16 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
|
echo "host all all 172.17.0.0/16 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
|
||||||
|
|
|
@ -35,18 +35,17 @@ fi
|
||||||
|
|
||||||
# Make sure we have a user set up
|
# Make sure we have a user set up
|
||||||
if [ -z "$USERNAME" ]; then
|
if [ -z "$USERNAME" ]; then
|
||||||
USERNAME=postgis
|
USERNAME=docker
|
||||||
fi
|
fi
|
||||||
if [ -z "$PASS" ]; then
|
if [ -z "$PASS" ]; then
|
||||||
PASS=postgis
|
PASS=docker
|
||||||
#PASS=`pwgen -c -n -1 12`
|
|
||||||
fi
|
fi
|
||||||
# redirect user/pass into a file so we can echo it into
|
# redirect user/pass into a file so we can echo it into
|
||||||
# docker logs when container starts
|
# docker logs when container starts
|
||||||
# so that we can tell user their password
|
# so that we can tell user their password
|
||||||
echo "postgresql user: $USERNAME" > /tmp/PGPASSWORD.txt
|
echo "postgresql user: $USERNAME" > /tmp/PGPASSWORD.txt
|
||||||
echo "postgresql password: $PASS" >> /tmp/PGPASSWORD.txt
|
echo "postgresql password: $PASS" >> /tmp/PGPASSWORD.txt
|
||||||
$POSTGRES --single -D $DATADIR -c config_file=$CONF" <<< "CREATE USER $USERNAME WITH SUPERUSER ENCRYPTED PASSWORD '$PASS';
|
$POSTGRES --single -D $DATADIR -c config_file=$CONF <<< "CREATE USER $USERNAME WITH SUPERUSER ENCRYPTED PASSWORD '$PASS';"
|
||||||
|
|
||||||
trap "echo \"Sending SIGTERM to postgres\"; killall -s SIGTERM postgres" SIGTERM
|
trap "echo \"Sending SIGTERM to postgres\"; killall -s SIGTERM postgres" SIGTERM
|
||||||
|
|
||||||
|
@ -76,6 +75,7 @@ else
|
||||||
# Needed when importing old dumps using e.g ndims for constraints
|
# Needed when importing old dumps using e.g ndims for constraints
|
||||||
echo "Loading legacy sql"
|
echo "Loading legacy sql"
|
||||||
psql template_postgis -f $SQLDIR/legacy_minimal.sql
|
psql template_postgis -f $SQLDIR/legacy_minimal.sql
|
||||||
|
psql template_postgis -f $SQLDIR/legacy_gist.sql
|
||||||
echo "Granting on geometry columns"
|
echo "Granting on geometry columns"
|
||||||
psql template_postgis -c 'GRANT ALL ON geometry_columns TO PUBLIC;'
|
psql template_postgis -c 'GRANT ALL ON geometry_columns TO PUBLIC;'
|
||||||
echo "Granting on geography columns"
|
echo "Granting on geography columns"
|
||||||
|
|
Ładowanie…
Reference in New Issue