Skip to content

Commit 0f55625

Browse files
authored
Merge pull request docker-library#303 from infosiftr/10beta
Add 10~beta1
2 parents 74857f4 + 83ea443 commit 0f55625

18 files changed

+647
-20
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ env:
1212
- VERSION=9.3 VARIANT=alpine
1313
- VERSION=9.2
1414
- VERSION=9.2 VARIANT=alpine
15+
- VERSION=10
16+
- VERSION=10 VARIANT=alpine
1517

1618
install:
1719
- git clone https://github.com/docker-library/official-images.git ~/official-images

10/Dockerfile

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# vim:set ft=dockerfile:
2+
FROM debian:stretch
3+
4+
RUN set -ex; \
5+
if ! command -v gpg > /dev/null; then \
6+
apt-get update; \
7+
apt-get install -y --no-install-recommends \
8+
gnupg2 \
9+
dirmngr \
10+
; \
11+
rm -rf /var/lib/apt/lists/*; \
12+
fi
13+
14+
# explicitly set user/group IDs
15+
RUN groupadd -r postgres --gid=999 && useradd -r -g postgres --uid=999 postgres
16+
17+
# grab gosu for easy step-down from root
18+
ENV GOSU_VERSION 1.7
19+
RUN set -x \
20+
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
21+
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
22+
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
23+
&& export GNUPGHOME="$(mktemp -d)" \
24+
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
25+
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
26+
&& rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc \
27+
&& chmod +x /usr/local/bin/gosu \
28+
&& gosu nobody true \
29+
&& apt-get purge -y --auto-remove ca-certificates wget
30+
31+
# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
32+
RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \
33+
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
34+
ENV LANG en_US.utf8
35+
36+
RUN mkdir /docker-entrypoint-initdb.d
37+
38+
RUN set -ex; \
39+
# pub 4096R/ACCC4CF8 2011-10-13 [expires: 2019-07-02]
40+
# Key fingerprint = B97B 0AFC AA1A 47F0 44F2 44A0 7FCC 7D46 ACCC 4CF8
41+
# uid PostgreSQL Debian Repository
42+
key='B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8'; \
43+
export GNUPGHOME="$(mktemp -d)"; \
44+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
45+
gpg --export "$key" > /etc/apt/trusted.gpg.d/postgres.gpg; \
46+
rm -rf "$GNUPGHOME"; \
47+
apt-key list
48+
49+
ENV PG_MAJOR 10
50+
ENV PG_VERSION 10~beta1-1.pgdg90+1
51+
52+
RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
53+
54+
RUN apt-get update \
55+
&& apt-get install -y postgresql-common \
56+
&& sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \
57+
&& apt-get install -y \
58+
postgresql-$PG_MAJOR=$PG_VERSION \
59+
&& rm -rf /var/lib/apt/lists/*
60+
61+
# make the sample config easier to munge (and "correct by default")
62+
RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/postgresql/ \
63+
&& ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
64+
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample
65+
66+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 2777 /var/run/postgresql
67+
68+
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
69+
ENV PGDATA /var/lib/postgresql/data
70+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA" # this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
71+
VOLUME /var/lib/postgresql/data
72+
73+
COPY docker-entrypoint.sh /usr/local/bin/
74+
RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat
75+
ENTRYPOINT ["docker-entrypoint.sh"]
76+
77+
EXPOSE 5432
78+
CMD ["postgres"]

10/alpine/Dockerfile

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# vim:set ft=dockerfile:
2+
FROM alpine:3.6
3+
4+
# alpine includes "postgres" user/group in base install
5+
# /etc/passwd:22:postgres:x:70:70::/var/lib/postgresql:/bin/sh
6+
# /etc/group:34:postgres:x:70:
7+
# the home directory for the postgres user, however, is not created by default
8+
# see https://github.com/docker-library/postgres/issues/274
9+
RUN set -ex; \
10+
postgresHome="$(getent passwd postgres)"; \
11+
postgresHome="$(echo "$postgresHome" | cut -d: -f6)"; \
12+
[ "$postgresHome" = '/var/lib/postgresql' ]; \
13+
mkdir -p "$postgresHome"; \
14+
chown -R postgres:postgres "$postgresHome"
15+
16+
# su-exec (gosu-compatible) is installed further down
17+
18+
# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
19+
# alpine doesn't require explicit locale-file generation
20+
ENV LANG en_US.utf8
21+
22+
RUN mkdir /docker-entrypoint-initdb.d
23+
24+
ENV PG_MAJOR 10
25+
ENV PG_VERSION 10beta1
26+
ENV PG_SHA256 7eee02e6f6646c7d4d6e78893a4ff638cfa5f1025b706712da8c6ef2257b5e29
27+
28+
RUN set -ex \
29+
\
30+
&& apk add --no-cache --virtual .fetch-deps \
31+
ca-certificates \
32+
openssl \
33+
tar \
34+
\
35+
&& wget -O postgresql.tar.bz2 "https://ftp.postgresql.org/pub/source/v$PG_VERSION/postgresql-$PG_VERSION.tar.bz2" \
36+
&& echo "$PG_SHA256 *postgresql.tar.bz2" | sha256sum -c - \
37+
&& mkdir -p /usr/src/postgresql \
38+
&& tar \
39+
--extract \
40+
--file postgresql.tar.bz2 \
41+
--directory /usr/src/postgresql \
42+
--strip-components 1 \
43+
&& rm postgresql.tar.bz2 \
44+
\
45+
&& apk add --no-cache --virtual .build-deps \
46+
bison \
47+
coreutils \
48+
dpkg-dev dpkg \
49+
flex \
50+
gcc \
51+
# krb5-dev \
52+
libc-dev \
53+
libedit-dev \
54+
libxml2-dev \
55+
libxslt-dev \
56+
make \
57+
# openldap-dev \
58+
openssl-dev \
59+
# configure: error: prove not found
60+
perl-utils \
61+
# perl-dev \
62+
# python-dev \
63+
# python3-dev \
64+
# tcl-dev \
65+
util-linux-dev \
66+
zlib-dev \
67+
\
68+
&& cd /usr/src/postgresql \
69+
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
70+
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
71+
&& awk '$1 == "#define" && $2 == "DEFAULT_PGSOCKET_DIR" && $3 == "\"/tmp\"" { $3 = "\"/var/run/postgresql\""; print; next } { print }' src/include/pg_config_manual.h > src/include/pg_config_manual.h.new \
72+
&& grep '/var/run/postgresql' src/include/pg_config_manual.h.new \
73+
&& mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h \
74+
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
75+
# explicitly update autoconf config.guess and config.sub so they support more arches/libcs
76+
&& wget -O config/config.guess 'https://git.savannah.gnu.org/cgit/config.git/plain/config.guess?id=7d3d27baf8107b630586c962c057e22149653deb' \
77+
&& wget -O config/config.sub 'https://git.savannah.gnu.org/cgit/config.git/plain/config.sub?id=7d3d27baf8107b630586c962c057e22149653deb' \
78+
# configure options taken from:
79+
# https://anonscm.debian.org/cgit/pkg-postgresql/postgresql.git/tree/debian/rules?h=9.5
80+
&& ./configure \
81+
--build="$gnuArch" \
82+
# "/usr/src/postgresql/src/backend/access/common/tupconvert.c:105: undefined reference to `libintl_gettext'"
83+
# --enable-nls \
84+
--enable-integer-datetimes \
85+
--enable-thread-safety \
86+
--enable-tap-tests \
87+
# skip debugging info -- we want tiny size instead
88+
# --enable-debug \
89+
--disable-rpath \
90+
--with-uuid=e2fs \
91+
--with-gnu-ld \
92+
--with-pgport=5432 \
93+
--with-system-tzdata=/usr/share/zoneinfo \
94+
--prefix=/usr/local \
95+
--with-includes=/usr/local/include \
96+
--with-libraries=/usr/local/lib \
97+
\
98+
# these make our image abnormally large (at least 100MB larger), which seems uncouth for an "Alpine" (ie, "small") variant :)
99+
# --with-krb5 \
100+
# --with-gssapi \
101+
# --with-ldap \
102+
# --with-tcl \
103+
# --with-perl \
104+
# --with-python \
105+
# --with-pam \
106+
--with-openssl \
107+
--with-libxml \
108+
--with-libxslt \
109+
&& make -j "$(nproc)" world \
110+
&& make install-world \
111+
&& make -C contrib install \
112+
\
113+
&& runDeps="$( \
114+
scanelf --needed --nobanner --recursive /usr/local \
115+
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
116+
| sort -u \
117+
| xargs -r apk info --installed \
118+
| sort -u \
119+
)" \
120+
&& apk add --no-cache --virtual .postgresql-rundeps \
121+
$runDeps \
122+
bash \
123+
su-exec \
124+
# tzdata is optional, but only adds around 1Mb to image size and is recommended by Django documentation:
125+
# https://docs.djangoproject.com/en/1.10/ref/databases/#optimizing-postgresql-s-configuration
126+
tzdata \
127+
&& apk del .fetch-deps .build-deps \
128+
&& cd / \
129+
&& rm -rf \
130+
/usr/src/postgresql \
131+
/usr/local/share/doc \
132+
/usr/local/share/man \
133+
&& find /usr/local -name '*.a' -delete
134+
135+
# make the sample config easier to munge (and "correct by default")
136+
RUN sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/local/share/postgresql/postgresql.conf.sample
137+
138+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 2777 /var/run/postgresql
139+
140+
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
141+
ENV PGDATA /var/lib/postgresql/data
142+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 777 "$PGDATA" # this 777 will be replaced by 700 at runtime (allows semi-arbitrary "--user" values)
143+
VOLUME /var/lib/postgresql/data
144+
145+
COPY docker-entrypoint.sh /usr/local/bin/
146+
RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat
147+
ENTRYPOINT ["docker-entrypoint.sh"]
148+
149+
EXPOSE 5432
150+
CMD ["postgres"]

10/alpine/docker-entrypoint.sh

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# usage: file_env VAR [DEFAULT]
5+
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
6+
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
7+
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
8+
file_env() {
9+
local var="$1"
10+
local fileVar="${var}_FILE"
11+
local def="${2:-}"
12+
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
13+
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
14+
exit 1
15+
fi
16+
local val="$def"
17+
if [ "${!var:-}" ]; then
18+
val="${!var}"
19+
elif [ "${!fileVar:-}" ]; then
20+
val="$(< "${!fileVar}")"
21+
fi
22+
export "$var"="$val"
23+
unset "$fileVar"
24+
}
25+
26+
if [ "${1:0:1}" = '-' ]; then
27+
set -- postgres "$@"
28+
fi
29+
30+
# allow the container to be started with `--user`
31+
if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
32+
mkdir -p "$PGDATA"
33+
chown -R postgres "$PGDATA"
34+
chmod 700 "$PGDATA"
35+
36+
mkdir -p /var/run/postgresql
37+
chown -R postgres /var/run/postgresql
38+
chmod 775 /var/run/postgresql
39+
40+
# Create the transaction log directory before initdb is run (below) so the directory is owned by the correct user
41+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
42+
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
43+
chown -R postgres "$POSTGRES_INITDB_XLOGDIR"
44+
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
45+
fi
46+
47+
exec su-exec postgres "$BASH_SOURCE" "$@"
48+
fi
49+
50+
if [ "$1" = 'postgres' ]; then
51+
mkdir -p "$PGDATA"
52+
chown -R "$(id -u)" "$PGDATA" 2>/dev/null || :
53+
chmod 700 "$PGDATA" 2>/dev/null || :
54+
55+
# look specifically for PG_VERSION, as it is expected in the DB dir
56+
if [ ! -s "$PGDATA/PG_VERSION" ]; then
57+
file_env 'POSTGRES_INITDB_ARGS'
58+
if [ "$POSTGRES_INITDB_XLOGDIR" ]; then
59+
export POSTGRES_INITDB_ARGS="$POSTGRES_INITDB_ARGS --xlogdir $POSTGRES_INITDB_XLOGDIR"
60+
fi
61+
eval "initdb --username=postgres $POSTGRES_INITDB_ARGS"
62+
63+
# check password first so we can output the warning before postgres
64+
# messes it up
65+
file_env 'POSTGRES_PASSWORD'
66+
if [ "$POSTGRES_PASSWORD" ]; then
67+
pass="PASSWORD '$POSTGRES_PASSWORD'"
68+
authMethod=md5
69+
else
70+
# The - option suppresses leading tabs but *not* spaces. :)
71+
cat >&2 <<-'EOWARN'
72+
****************************************************
73+
WARNING: No password has been set for the database.
74+
This will allow anyone with access to the
75+
Postgres port to access your database. In
76+
Docker's default configuration, this is
77+
effectively any other container on the same
78+
system.
79+
80+
Use "-e POSTGRES_PASSWORD=password" to set
81+
it in "docker run".
82+
****************************************************
83+
EOWARN
84+
85+
pass=
86+
authMethod=trust
87+
fi
88+
89+
{
90+
echo
91+
echo "host all all all $authMethod"
92+
} >> "$PGDATA/pg_hba.conf"
93+
94+
# internal start of server in order to allow set-up using psql-client
95+
# does not listen on external TCP/IP and waits until start finishes
96+
PGUSER="${PGUSER:-postgres}" \
97+
pg_ctl -D "$PGDATA" \
98+
-o "-c listen_addresses='localhost'" \
99+
-w start
100+
101+
file_env 'POSTGRES_USER' 'postgres'
102+
file_env 'POSTGRES_DB' "$POSTGRES_USER"
103+
104+
psql=( psql -v ON_ERROR_STOP=1 )
105+
106+
if [ "$POSTGRES_DB" != 'postgres' ]; then
107+
"${psql[@]}" --username postgres <<-EOSQL
108+
CREATE DATABASE "$POSTGRES_DB" ;
109+
EOSQL
110+
echo
111+
fi
112+
113+
if [ "$POSTGRES_USER" = 'postgres' ]; then
114+
op='ALTER'
115+
else
116+
op='CREATE'
117+
fi
118+
"${psql[@]}" --username postgres <<-EOSQL
119+
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
120+
EOSQL
121+
echo
122+
123+
psql+=( --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" )
124+
125+
echo
126+
for f in /docker-entrypoint-initdb.d/*; do
127+
case "$f" in
128+
*.sh) echo "$0: running $f"; . "$f" ;;
129+
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
130+
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
131+
*) echo "$0: ignoring $f" ;;
132+
esac
133+
echo
134+
done
135+
136+
PGUSER="${PGUSER:-postgres}" \
137+
pg_ctl -D "$PGDATA" -m fast -w stop
138+
139+
echo
140+
echo 'PostgreSQL init process complete; ready for start up.'
141+
echo
142+
fi
143+
fi
144+
145+
exec "$@"

0 commit comments

Comments
 (0)