dockerfiles needs your help reporting errors, bugs and usability feedback. If you encounter an error, please post on the Issue tracker.


Postgresql from source.

  • Postgresql from official git VCS.
  • Adjustable version by updating git checkout tag.
  • Support for python, tcl, perl.
  • Support for init.d service.
  • Pure Dockerfile, no external shell scripts.

This Dockerfile compiles postgres from git and sets up a service with the username and password docker and docker.

Currently it uses the release 9.3.1.

The version can be adjusted by modifying the git checkout REL9_3_1 in the Dockerfile.

Building and debugging

sudo docker build -t="postgresql" .
$   sudo docker run -i -t postgresql /bin/bash

# and when inside:
$   service postgresql start


$   CONTAINER=$(sudo docker run -d -p 5432 \
    -t postgresql)

$   CONTAINER_IP=$(sudo docker inspect $CONTAINER | grep IPAddress | \
    awk '{ print $2 }' | tr -d ',"')

# on your local machine postgres' client
$   psql -p5432 -h $CONTAINER_IP --username='docker' --password --list


FROM ubuntu
#FROM stackbrew/ubuntu:13.10
#MAINTAINER Tony Narlock <>


RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install build-essential -y
RUN apt-get install libreadline-dev zlib1g-dev flex bison libxml2-dev \
    libfl-dev libxslt1-dev libssl-dev libfl-dev python2.7-dev python-dev \
    libpam-dev tcl-dev libperl-dev git -y
RUN git clone git://
RUN cd postgresql && git checkout REL9_3_1
RUN cd postgresql && ./configure --with-tcl --with-perl --with-python \
    --with-pam --with-openssl --with-libxml --with-libxslt \
    --mandir=/usr/local/share/postgresql/man \
    --docdir=/usr/local/share/doc/postgresql-doc \
    --sysconfdir=/etc/postgresql-common \
    --datarootdir=/usr/local/share \
    --datadir=/usr/local/share/postgresql \
    --bindir=/usr/local/lib/postgresql/bin \
    --libdir=/usr/local/lib \
    --libexecdir=/usr/local/lib/postgresql \
    --includedir=/usr/local/include/postgresql \
    --with-pgport=5432 \
    --enable-integer-datetimes \
    --enable-thread-safety \
    --enable-debug \
    --disable-rpath \
RUN cd postgresql && make
RUN cd postgresql && make install
RUN cd postgresql/contrib make all
RUN cd postgresql/contrib make install
RUN cp postgresql/contrib/start-scripts/linux /etc/init.d/postgresql 
RUN sed -i 's,/usr/local/pgsql/data,/var/lib/postgresql/data,g' /etc/init.d/postgresql
RUN sed -i 's,/usr/local/pgsql,/usr/local/lib/postgresql,g' /etc/init.d/postgresql

RUN chmod +x /etc/init.d/postgresql
RUN update-rc.d postgresql defaults
RUN echo 'PATH=$PATH:/usr/local/lib/postgresql/bin; export PATH' > /etc/profile.d/
RUN echo 'MANPATH=$MANPATH:/usr/local/postgresql/man; export MANPATH' >> /etc/profile.d/
RUN chmod 775 /etc/profile.d/
RUN chmod 775 /etc/profile.d/
RUN . /etc/profile
RUN adduser postgres --disabled-password --gecos ""
RUN mkdir -p /var/log/postgresql
RUN chown -R postgres:postgres /var/log/postgresql

RUN mkdir -p /var/lib/postgresql/data
RUN chown -R postgres:postgres /var/lib/postgresql/data
RUN /sbin/ldconfig /usr/local/lib/postgresql
RUN su - postgres -c "/usr/local/lib/postgresql/bin/initdb \
    -D /var/lib/postgresql/data"
    su postgres sh -c "/usr/local/lib/postgresql/bin/postgres --single \
    -D /var/lib/postgresql/data \
    -c config_file=/var/lib/postgresql/data/postgresql.conf"

RUN echo "host    all     all     trust" >> /var/lib/postgresql/data/pg_hba.conf
RUN echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf

CMD service postgresql start && tail -F /var/lib/postgresql/data/serverlog