mirror of
https://github.com/wassname/docker-postgresql.git
synced 2026-09-09 11:21:30 +08:00
initial creation
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
|||||||
|
FROM ubuntu:12.04
|
||||||
|
MAINTAINER sameer@damagehead.com
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
|
RUN sed 's/main$/main universe/' -i /etc/apt/sources.list
|
||||||
|
RUN apt-get update # 20140409
|
||||||
|
|
||||||
|
# Fix some issues with APT packages.
|
||||||
|
# See https://github.com/dotcloud/docker/issues/1024
|
||||||
|
RUN dpkg-divert --local --rename --add /sbin/initctl && \
|
||||||
|
ln -sf /bin/true /sbin/initctl
|
||||||
|
|
||||||
|
# essentials
|
||||||
|
RUN apt-get install -y vim curl wget sudo net-tools pwgen unzip \
|
||||||
|
logrotate supervisor openssh-server && apt-get clean
|
||||||
|
|
||||||
|
# build tools
|
||||||
|
# RUN apt-get install -y gcc make && apt-get clean
|
||||||
|
|
||||||
|
# image specific
|
||||||
|
RUN apt-get install -y postgresql-9.1 postgresql-client-9.1 && apt-get clean
|
||||||
|
|
||||||
|
ADD assets/ /app/
|
||||||
|
RUN mv /app/.vimrc /app/.bash_aliases /root/
|
||||||
|
RUN chmod 755 /app/init /app/setup/install && /app/setup/install
|
||||||
|
|
||||||
|
ADD authorized_keys /root/.ssh/
|
||||||
|
RUN chmod 700 /root/.ssh && chmod 600 /root/.ssh/authorized_keys && chown root:root -R /root/.ssh
|
||||||
|
|
||||||
|
EXPOSE 22
|
||||||
|
EXPOSE 5432
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app/init"]
|
||||||
|
CMD ["app:start"]
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
PS1='${debian_chroot:+($debian_chroot)}[\u@\h \W]# '
|
||||||
|
|
||||||
|
alias rm='rm -i'
|
||||||
|
alias cp='cp -i'
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
se ai
|
||||||
|
se sw=2 ts=2
|
||||||
Executable
+73
@@ -0,0 +1,73 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# generate a password for root.
|
||||||
|
ROOT_PASSWORD=$(pwgen -c -n -1 12)
|
||||||
|
echo "root:$ROOT_PASSWORD" | chpasswd
|
||||||
|
echo User: root Password: $ROOT_PASSWORD
|
||||||
|
|
||||||
|
# start supervisord
|
||||||
|
/usr/bin/supervisord
|
||||||
|
|
||||||
|
appStart () {
|
||||||
|
# fix permissions and ownership of /var/lib/postgresql
|
||||||
|
chown -R postgres:postgres /var/lib/postgresql
|
||||||
|
chmod 700 /var/lib/postgresql
|
||||||
|
|
||||||
|
# initialize PostgreSQL data directory
|
||||||
|
if [ ! -d /var/lib/postgresql/9.1/main ]; then
|
||||||
|
echo "Initializing database..."
|
||||||
|
PG_PASSWORD=$(pwgen -c -n -1 14)
|
||||||
|
echo "${PG_PASSWORD}" > /var/lib/postgresql/pwfile
|
||||||
|
sudo -u postgres -H /usr/lib/postgresql/9.1/bin/initdb \
|
||||||
|
--pgdata=/var/lib/postgresql/9.1/main --pwfile=/var/lib/postgresql/pwfile \
|
||||||
|
--username=postgres --encoding=unicode --auth=trust >/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Starting PostgreSQL server..."
|
||||||
|
/etc/init.d/postgresql start
|
||||||
|
|
||||||
|
if [ -f /var/lib/postgresql/pwfile ]; then
|
||||||
|
PG_PASSWORD=$(cat /var/lib/postgresql/pwfile)
|
||||||
|
echo "|------------------------------------------------------------------|"
|
||||||
|
echo "| PostgreSQL User: postgres, Password: ${PG_PASSWORD} |"
|
||||||
|
echo "| |"
|
||||||
|
echo "| To remove the PostgreSQL login credentials from the logs, please |"
|
||||||
|
echo "| make a note of password and then delete the file pwfile |"
|
||||||
|
echo "| from the data store. |"
|
||||||
|
echo "|------------------------------------------------------------------|"
|
||||||
|
fi
|
||||||
|
tail -F /var/log/postgresql/postgresql-9.1-main.log
|
||||||
|
}
|
||||||
|
|
||||||
|
appHelp () {
|
||||||
|
echo "Available options:"
|
||||||
|
echo " app:start - Start the postgresql server and watch the log (default)"
|
||||||
|
echo " app:help - Displays the help"
|
||||||
|
echo " [command] - Execute the specified linux command eg. bash."
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
app:start)
|
||||||
|
appStart
|
||||||
|
;;
|
||||||
|
app:help)
|
||||||
|
appHelp
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [ -x $1 ]; then
|
||||||
|
$1
|
||||||
|
else
|
||||||
|
prog=$(which $1)
|
||||||
|
if [ -n "${prog}" ] ; then
|
||||||
|
shift 1
|
||||||
|
$prog $@
|
||||||
|
else
|
||||||
|
appHelp
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
mkdir -p /var/run/sshd
|
||||||
|
cat > /etc/supervisor/conf.d/sshd.conf <<EOF
|
||||||
|
[program:sshd]
|
||||||
|
directory=/
|
||||||
|
command=/usr/sbin/sshd -D
|
||||||
|
user=root
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
stdout_logfile=/var/log/supervisor/%(program_name)s.log
|
||||||
|
stderr_logfile=/var/log/supervisor/%(program_name)s_error.log
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# listen on all interfaces
|
||||||
|
cat >> /etc/postgresql/9.1/main/postgresql.conf <<EOF
|
||||||
|
listen_addresses = '*'
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# allow remote connections to postgresql database
|
||||||
|
cat >> /etc/postgresql/9.1/main/pg_hba.conf <<EOF
|
||||||
|
host all all 0.0.0.0/0 md5
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# remove the default database, will create from init
|
||||||
|
rm -rf /var/lib/postgresql/9.1/main
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "*************************************************************************"
|
||||||
|
echo "* Please login to postgresql and create the required database and *"
|
||||||
|
echo "* database user with remote login access so that other containers can *"
|
||||||
|
echo "* use it. *"
|
||||||
|
echo "* *"
|
||||||
|
echo "* e.g. *"
|
||||||
|
echo "* sudo -u postgres createuser db_user *"
|
||||||
|
echo "* sudo -u postgres psql *"
|
||||||
|
echo "* > \password db_user *"
|
||||||
|
echo "* sudo -u postgres createdb -O db_user db_name *"
|
||||||
|
echo "*************************************************************************"
|
||||||
|
echo ""
|
||||||
Reference in New Issue
Block a user