Skip to content

Instantly share code, notes, and snippets.

@Su-Shee
Last active August 7, 2022 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Su-Shee/219d00953b6ec7a44c4e01ce616f4522 to your computer and use it in GitHub Desktop.
Save Su-Shee/219d00953b6ec7a44c4e01ce616f4522 to your computer and use it in GitHub Desktop.
Build Postgres in Docker
FROM ubuntu:16.10
# update the repository
RUN apt-get update --fix-missing
# install some basics
RUN apt-get install -y vim curl wget dialog net-tools \
build-essential strace \
perl libperl-dev python python-dev libxml2-dev libxslt-dev \
libreadline-dev zlib1g-dev \
libosp5 uuid-dev libossp-uuid-dev libossp-uuid16 \
openssl libssl-dev
# fetch postgres source
RUN wget https://ftp.postgresql.org/pub/source/v9.6.2/postgresql-9.6.2.tar.bz2
# unpack
RUN tar jxfv postgresql-9.6.2.tar.bz2
# configure and build
RUN cd postgresql-9.6.2 && ./configure \
--with-openssl \
--with-perl \
--with-python \
--with-uuid=e2fs \
--with-libxml \
--with-libxslt \
--enable-thread-safety && make && make install
ENV PG_EXTENSIONS "adminpack pgcrypto hstore ltree \
xml2 cube btree_gin btree_gist \
fuzzystrmatch pg_standby postgres_fdw \
file_fdw uuid-ossp pg_trgm unaccent bloom"
RUN cd postgresql-9.6.2/contrib; \
for ext in $PG_EXTENSIONS; \
do cd ./$ext && make install; \
cd ..; \
done
ENV PG_HOME /usr/local/pgsql
ENV PG_USER postgres
ENV PG_GROUP postgres
ENV PGDATA /usr/local/pgsql/data
ENV PATH $PATH:/usr/local/pgsql/bin
RUN groupadd $PG_GROUP
RUN useradd -g $PG_GROUP -d $PG_HOME -c PostgreSQL $PG_USER
RUN mkdir -p $PG_HOME/data
RUN chown -R $PG_USER:$PG_GROUP $PG_HOME
RUN chmod 700 $PG_HOME
RUN chmod 700 $PG_HOME/data
# now things can run as proper user
USER postgres
# database storage init
RUN /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
# basic postgres config
COPY postgresql.conf /usr/local/pgsql/data
COPY pg_hba.conf /usr/local/pgsql/data
# expose ports
EXPOSE 5432
# start the whole thing
#RUN ["/usr/local/pgsql/bin/pg_ctl", "-D", "/usr/local/pgsql/data", "start"]
#RUN /usr/local/pgsql/bin/postgres
# that doesn't start pg at all, no daemon running, no nothing, netstat no ports
# if I call docker like this:
# docker run -d --name postgres -p :5432:5432 -t postgres /bin/su postgres -c '/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data start'
# I get at least a running postgres, netstat showsport etc
# and, after your advice, I listen to 0.0.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment