kopia lustrzana https://github.com/kartoza/docker-postgis
Merge pull request #9 from anentropic/issue/8-default-user
avoid name collision of env var so default docker user can be createdpull/30/head
commit
f01979c338
|
@ -67,8 +67,8 @@ sudo docker run --name "postgis" -p 25432:5432 -d -t kartoza/postgis
|
||||||
You can also use the following environment variables to pass a
|
You can also use the following environment variables to pass a
|
||||||
user name and password.
|
user name and password.
|
||||||
|
|
||||||
* -e USERNAME=<PGUSER>
|
* -e POSTGRES_USER=<PGUSER>
|
||||||
* -e PASS=<PGPASSWORD>
|
* -e POSTGRES_PASS=<PGPASSWORD>
|
||||||
|
|
||||||
These will be used to create a new superuser with
|
These will be used to create a new superuser with
|
||||||
your preferred credentials. If these are not specified then the postgresql
|
your preferred credentials. If these are not specified then the postgresql
|
||||||
|
|
|
@ -26,7 +26,7 @@ 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"
|
CMD="docker run -cidfile="$IDFILE" -name="postgis" -e POSTGRES_USER=$PGUSER -e POSTGRES_PASS=$PGPASS -d -v $HOST_DATA_DIR:/var/lib/postgresql -t qgis/postgis:$VERSION /start.sh"
|
||||||
echo 'Running:'
|
echo 'Running:'
|
||||||
echo $CMD
|
echo $CMD
|
||||||
eval $CMD
|
eval $CMD
|
||||||
|
|
|
@ -65,8 +65,8 @@ docker rm ${CONTAINER_NAME}
|
||||||
CMD="docker run --name="${CONTAINER_NAME}" \
|
CMD="docker run --name="${CONTAINER_NAME}" \
|
||||||
--hostname="${CONTAINER_NAME}" \
|
--hostname="${CONTAINER_NAME}" \
|
||||||
--restart=always \
|
--restart=always \
|
||||||
-e USERNAME=${PGUSER} \
|
-e POSTGRES_USER=${PGUSER} \
|
||||||
-e PASS=${PGPASSWORD} \
|
-e POSTGRES_PASS=${PGPASSWORD} \
|
||||||
-d -t \
|
-d -t \
|
||||||
${VOLUME_OPTION} \
|
${VOLUME_OPTION} \
|
||||||
kartoza/postgis /start-postgis.sh"
|
kartoza/postgis /start-postgis.sh"
|
||||||
|
@ -79,7 +79,7 @@ docker ps | grep ${CONTAINER_NAME}
|
||||||
|
|
||||||
echo "Connect using:"
|
echo "Connect using:"
|
||||||
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 $PGPASSWORD"
|
||||||
echo
|
echo
|
||||||
echo "Alternatively link to this container from another to access it"
|
echo "Alternatively link to this container from another to access it"
|
||||||
echo "e.g. docker run -link postgis:pg .....etc"
|
echo "e.g. docker run -link postgis:pg .....etc"
|
||||||
|
|
|
@ -25,9 +25,9 @@ fi
|
||||||
# needs to be done as root:
|
# needs to be done as root:
|
||||||
chown -R postgres:postgres $DATADIR
|
chown -R postgres:postgres $DATADIR
|
||||||
|
|
||||||
# Note that $USERNAME and $PASS below are optional paramters that can be passed
|
# Note that $POSTGRES_USER and $POSTGRES_PASS below are optional paramters that can be passed
|
||||||
# via docker run e.g.
|
# via docker run e.g.
|
||||||
#docker run --name="postgis" -e USERNAME=qgis -e PASS=qgis -d -v
|
#docker run --name="postgis" -e POSTGRES_USER=qgis -e POSTGRES_PASS=qgis -d -v
|
||||||
#/var/docker-data/postgres-dat:/var/lib/postgresql -t qgis/postgis:6
|
#/var/docker-data/postgres-dat:/var/lib/postgresql -t qgis/postgis:6
|
||||||
|
|
||||||
# If you dont specify a user/password in docker run, we will generate one
|
# If you dont specify a user/password in docker run, we will generate one
|
||||||
|
@ -45,18 +45,18 @@ if [ ! "$(ls -A $DATADIR)" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Make sure we have a user set up
|
# Make sure we have a user set up
|
||||||
if [ -z "$USERNAME" ]; then
|
if [ -z "$POSTGRES_USER" ]; then
|
||||||
USERNAME=docker
|
POSTGRES_USER=docker
|
||||||
fi
|
fi
|
||||||
if [ -z "$PASS" ]; then
|
if [ -z "$POSTGRES_PASS" ]; then
|
||||||
PASS=docker
|
POSTGRES_PASS=docker
|
||||||
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: $POSTGRES_USER" > /tmp/PGPASSWORD.txt
|
||||||
echo "postgresql password: $PASS" >> /tmp/PGPASSWORD.txt
|
echo "postgresql password: $POSTGRES_PASS" >> /tmp/PGPASSWORD.txt
|
||||||
su - postgres -c "$POSTGRES --single -D $DATADIR -c config_file=$CONF <<< \"CREATE USER $USERNAME WITH SUPERUSER ENCRYPTED PASSWORD '$PASS';\""
|
su - postgres -c "$POSTGRES --single -D $DATADIR -c config_file=$CONF <<< \"CREATE USER $POSTGRES_USER WITH SUPERUSER ENCRYPTED PASSWORD '$POSTGRES_PASS';\""
|
||||||
|
|
||||||
trap "echo \"Sending SIGTERM to postgres\"; killall -s SIGTERM postgres" SIGTERM
|
trap "echo \"Sending SIGTERM to postgres\"; killall -s SIGTERM postgres" SIGTERM
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue