From 15d12844946d27dec68387f6279231867b5e9a2d Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 12 Dec 2013 16:08:48 -0800 Subject: [PATCH] postgresql: Add PostgreSQL container instructions (Dockerfile and README) The $(echo /etc/postgresql*/postgresql.conf) crazyness in the Dockerfile is because Docker chokes on: RUN echo host all all 0.0.0.0/0 trust >> /etc/postgresql*/pg_hba.conf raising: /bin/sh: /etc/postgresql*/pg_hba.conf: No such file or directory I'm not sure why it's not expanding the glob. Perhaps Docker is quoting redirection targets? In any case, the $(echo ...) form works, so that's what I'm going with for now. --- README.md | 1 + build.sh | 1 + postgresql/Dockerfile.template | 41 ++++++++++++++++++++++++++++ postgresql/README.md | 50 ++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 postgresql/Dockerfile.template create mode 100644 postgresql/README.md diff --git a/README.md b/README.md index 95d562b..a946d79 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ The dependency graph is: `-- gentoo-en-us (adds locale) `-- gentoo-syslog (adds syslog-ng and associates) |-- buildbot (adds a Buildbot master and slave) + |-- postgresql (adds PostgreSQL) `-- redis (adds Redis) Run: diff --git a/build.sh b/build.sh index ace1ef0..6b1a05a 100755 --- a/build.sh +++ b/build.sh @@ -39,6 +39,7 @@ REPOS=" gentoo-en-us gentoo-syslog buildbot + postgresql redis " diff --git a/postgresql/Dockerfile.template b/postgresql/Dockerfile.template new file mode 100644 index 0000000..456cf09 --- /dev/null +++ b/postgresql/Dockerfile.template @@ -0,0 +1,41 @@ +# Copyright (C) 2013 W. Trevor King +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +FROM NAMESPACE/gentoo-syslog:TAG +MAINTAINER A. U. Thor +#VOLUME ["PORTAGE:/usr/portage:ro", "PORTAGE/distfiles:/usr/portage/distfiles:rw"] +RUN emerge -v dev-db/postgresql-server +RUN eselect news read new +RUN rc-update add $(basename /etc/init.d/postgresql-*) default +RUN yes | emerge --config dev-db/postgresql-server + +# Expose PostgreSQL to external network connections +RUN echo "listen_addresses = '*'" >> $(echo /etc/postgresql*/postgresql.conf) +RUN echo host all all 0.0.0.0/0 trust >> $(echo /etc/postgresql*/pg_hba.conf) + +# Container networking happens automatically +RUN sed -i 's/need net$/use net/' /etc/init.d/* + +CMD rc default && tail -F /var/log/messages +EXPOSE 5432 diff --git a/postgresql/README.md b/postgresql/README.md new file mode 100644 index 0000000..ea70519 --- /dev/null +++ b/postgresql/README.md @@ -0,0 +1,50 @@ +Run this [PostgreSQL][] image with: + + $ docker run -d -name postgresql-0 wking/postgresql + +Then [link][linking] to it from your client container: + + $ docker run -link postgresql-0:postgresql your-client + +For example, we can use the PostgreSQL client in the +`wking/postgresql` image itself: + + $ docker run -link postgresql-0:postgresql -i -t wking/postgresql /bin/bash + 94ca64e60a00 / # HOST_PORT="${POSTGRESQL_PORT#[a-z]*://}" + 94ca64e60a00 / # HOST="${HOST_PORT%:[0-9]*}" + 94ca64e60a00 / # PORT="${HOST_PORT#[0-9.]*:}" + 94ca64e60a00 / # psql -h "${HOST}" -p "${PORT}" -U postgres + psql (9.2.4) + Type "help" for help. + + postgres=# help + You are using psql, the command-line interface to PostgreSQL. + … + +The exposed port is not proxied by the host: + + $ docker port postgresql-0 5432 + 2013/12/12 15:56:28 Error: No public port '5432' published for postgresql-0 + +But you can access it if you know the IP: + + $ psql -h 10.0.0.12 -p 5432 -U postgres + psql (9.2.4) + Type "help" for help. + + postgres=# + +You can also access it from unlinked containers: + + $ docker run -i -t wking/postgresql /bin/bash + 8ee7a0597619 / # psql -h 10.0.0.12 -p 5432 -U postgres + psql (9.2.4) + Type "help" for help. + + postgres=# … + +Basically, anyone with access to the `docker0` bridge has access to +the client's port. + +[PostgreSQL]: http://postgresql.io/ +[linking]: http://docs.docker.io/en/latest/use/port_redirection/#linking-a-container -- 2.26.2