Skip to content

Commit 03a6cb6

Browse files
authored
Merge pull request #252 from infosiftr/var/run/postgresql
Use "/var/run/postgresql" consistently (and apply Debian's change of the default socket path to Alpine also)
2 parents a7a6cdf + b68154e commit 03a6cb6

23 files changed

+109
-56
lines changed

9.2/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/post
5454
&& ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
5555
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample
5656

57-
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
57+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
5858

5959
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
6060
ENV PGDATA /var/lib/postgresql/data
61+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
6162
VOLUME /var/lib/postgresql/data
6263

6364
COPY docker-entrypoint.sh /

9.2/alpine/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ RUN set -ex \
5555
zlib-dev \
5656
\
5757
&& cd /usr/src/postgresql \
58+
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
59+
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
60+
&& 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 \
61+
&& grep '/var/run/postgresql' src/include/pg_config_manual.h.new \
62+
&& mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h \
5863
# configure options taken from:
5964
# https://anonscm.debian.org/cgit/pkg-postgresql/postgresql.git/tree/debian/rules?h=9.5
6065
&& ./configure \
@@ -113,10 +118,11 @@ RUN set -ex \
113118
# make the sample config easier to munge (and "correct by default")
114119
RUN sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/local/share/postgresql/postgresql.conf.sample
115120

116-
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
121+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
117122

118123
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
119124
ENV PGDATA /var/lib/postgresql/data
125+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
120126
VOLUME /var/lib/postgresql/data
121127

122128
COPY docker-entrypoint.sh /

9.2/alpine/docker-entrypoint.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ fi
2929

3030
if [ "$1" = 'postgres' ]; then
3131
mkdir -p "$PGDATA"
32-
chmod 700 "$PGDATA"
3332
chown -R postgres "$PGDATA"
33+
chmod 700 "$PGDATA"
34+
35+
mkdir -p /var/run/postgresql
36+
chown -R postgres /var/run/postgresql
37+
chmod g+s /var/run/postgresql
3438

35-
mkdir -p /run/postgresql
36-
chmod g+s /run/postgresql
37-
chown -R postgres /run/postgresql
3839

3940
# look specifically for PG_VERSION, as it is expected in the DB dir
4041
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.2/docker-entrypoint.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ fi
2929

3030
if [ "$1" = 'postgres' ]; then
3131
mkdir -p "$PGDATA"
32-
chmod 700 "$PGDATA"
3332
chown -R postgres "$PGDATA"
33+
chmod 700 "$PGDATA"
34+
35+
mkdir -p /var/run/postgresql
36+
chown -R postgres /var/run/postgresql
37+
chmod g+s /var/run/postgresql
3438

35-
mkdir -p /run/postgresql
36-
chmod g+s /run/postgresql
37-
chown -R postgres /run/postgresql
3839

3940
# look specifically for PG_VERSION, as it is expected in the DB dir
4041
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.3/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/post
5454
&& ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
5555
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample
5656

57-
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
57+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
5858

5959
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
6060
ENV PGDATA /var/lib/postgresql/data
61+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
6162
VOLUME /var/lib/postgresql/data
6263

6364
COPY docker-entrypoint.sh /

9.3/alpine/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ RUN set -ex \
5555
zlib-dev \
5656
\
5757
&& cd /usr/src/postgresql \
58+
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
59+
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
60+
&& 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 \
61+
&& grep '/var/run/postgresql' src/include/pg_config_manual.h.new \
62+
&& mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h \
5863
# configure options taken from:
5964
# https://anonscm.debian.org/cgit/pkg-postgresql/postgresql.git/tree/debian/rules?h=9.5
6065
&& ./configure \
@@ -113,10 +118,11 @@ RUN set -ex \
113118
# make the sample config easier to munge (and "correct by default")
114119
RUN sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/local/share/postgresql/postgresql.conf.sample
115120

116-
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
121+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
117122

118123
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
119124
ENV PGDATA /var/lib/postgresql/data
125+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
120126
VOLUME /var/lib/postgresql/data
121127

122128
COPY docker-entrypoint.sh /

9.3/alpine/docker-entrypoint.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ fi
2929

3030
if [ "$1" = 'postgres' ]; then
3131
mkdir -p "$PGDATA"
32-
chmod 700 "$PGDATA"
3332
chown -R postgres "$PGDATA"
33+
chmod 700 "$PGDATA"
34+
35+
mkdir -p /var/run/postgresql
36+
chown -R postgres /var/run/postgresql
37+
chmod g+s /var/run/postgresql
3438

35-
mkdir -p /run/postgresql
36-
chmod g+s /run/postgresql
37-
chown -R postgres /run/postgresql
3839

3940
# look specifically for PG_VERSION, as it is expected in the DB dir
4041
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.3/docker-entrypoint.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ fi
2929

3030
if [ "$1" = 'postgres' ]; then
3131
mkdir -p "$PGDATA"
32-
chmod 700 "$PGDATA"
3332
chown -R postgres "$PGDATA"
33+
chmod 700 "$PGDATA"
34+
35+
mkdir -p /var/run/postgresql
36+
chown -R postgres /var/run/postgresql
37+
chmod g+s /var/run/postgresql
3438

35-
mkdir -p /run/postgresql
36-
chmod g+s /run/postgresql
37-
chown -R postgres /run/postgresql
3839

3940
# look specifically for PG_VERSION, as it is expected in the DB dir
4041
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.4/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/post
5454
&& ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
5555
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample
5656

57-
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
57+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
5858

5959
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
6060
ENV PGDATA /var/lib/postgresql/data
61+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
6162
VOLUME /var/lib/postgresql/data
6263

6364
COPY docker-entrypoint.sh /

9.4/alpine/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ RUN set -ex \
5555
zlib-dev \
5656
\
5757
&& cd /usr/src/postgresql \
58+
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
59+
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
60+
&& 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 \
61+
&& grep '/var/run/postgresql' src/include/pg_config_manual.h.new \
62+
&& mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h \
5863
# configure options taken from:
5964
# https://anonscm.debian.org/cgit/pkg-postgresql/postgresql.git/tree/debian/rules?h=9.5
6065
&& ./configure \
@@ -113,10 +118,11 @@ RUN set -ex \
113118
# make the sample config easier to munge (and "correct by default")
114119
RUN sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/local/share/postgresql/postgresql.conf.sample
115120

116-
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
121+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
117122

118123
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
119124
ENV PGDATA /var/lib/postgresql/data
125+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
120126
VOLUME /var/lib/postgresql/data
121127

122128
COPY docker-entrypoint.sh /

9.4/alpine/docker-entrypoint.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ fi
2929

3030
if [ "$1" = 'postgres' ]; then
3131
mkdir -p "$PGDATA"
32-
chmod 700 "$PGDATA"
3332
chown -R postgres "$PGDATA"
33+
chmod 700 "$PGDATA"
34+
35+
mkdir -p /var/run/postgresql
36+
chown -R postgres /var/run/postgresql
37+
chmod g+s /var/run/postgresql
3438

35-
mkdir -p /run/postgresql
36-
chmod g+s /run/postgresql
37-
chown -R postgres /run/postgresql
3839

3940
# look specifically for PG_VERSION, as it is expected in the DB dir
4041
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.4/docker-entrypoint.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ fi
2929

3030
if [ "$1" = 'postgres' ]; then
3131
mkdir -p "$PGDATA"
32-
chmod 700 "$PGDATA"
3332
chown -R postgres "$PGDATA"
33+
chmod 700 "$PGDATA"
34+
35+
mkdir -p /var/run/postgresql
36+
chown -R postgres /var/run/postgresql
37+
chmod g+s /var/run/postgresql
3438

35-
mkdir -p /run/postgresql
36-
chmod g+s /run/postgresql
37-
chown -R postgres /run/postgresql
3839

3940
# look specifically for PG_VERSION, as it is expected in the DB dir
4041
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.5/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/post
5454
&& ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
5555
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample
5656

57-
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
57+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
5858

5959
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
6060
ENV PGDATA /var/lib/postgresql/data
61+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
6162
VOLUME /var/lib/postgresql/data
6263

6364
COPY docker-entrypoint.sh /

9.5/alpine/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ RUN set -ex \
5555
zlib-dev \
5656
\
5757
&& cd /usr/src/postgresql \
58+
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
59+
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
60+
&& 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 \
61+
&& grep '/var/run/postgresql' src/include/pg_config_manual.h.new \
62+
&& mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h \
5863
# configure options taken from:
5964
# https://anonscm.debian.org/cgit/pkg-postgresql/postgresql.git/tree/debian/rules?h=9.5
6065
&& ./configure \
@@ -113,10 +118,11 @@ RUN set -ex \
113118
# make the sample config easier to munge (and "correct by default")
114119
RUN sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/local/share/postgresql/postgresql.conf.sample
115120

116-
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
121+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
117122

118123
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
119124
ENV PGDATA /var/lib/postgresql/data
125+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
120126
VOLUME /var/lib/postgresql/data
121127

122128
COPY docker-entrypoint.sh /

9.5/alpine/docker-entrypoint.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ fi
2929

3030
if [ "$1" = 'postgres' ]; then
3131
mkdir -p "$PGDATA"
32-
chmod 700 "$PGDATA"
3332
chown -R postgres "$PGDATA"
33+
chmod 700 "$PGDATA"
34+
35+
mkdir -p /var/run/postgresql
36+
chown -R postgres /var/run/postgresql
37+
chmod g+s /var/run/postgresql
3438

35-
mkdir -p /run/postgresql
36-
chmod g+s /run/postgresql
37-
chown -R postgres /run/postgresql
3839

3940
# look specifically for PG_VERSION, as it is expected in the DB dir
4041
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.5/docker-entrypoint.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ fi
2929

3030
if [ "$1" = 'postgres' ]; then
3131
mkdir -p "$PGDATA"
32-
chmod 700 "$PGDATA"
3332
chown -R postgres "$PGDATA"
33+
chmod 700 "$PGDATA"
34+
35+
mkdir -p /var/run/postgresql
36+
chown -R postgres /var/run/postgresql
37+
chmod g+s /var/run/postgresql
3438

35-
mkdir -p /run/postgresql
36-
chmod g+s /run/postgresql
37-
chown -R postgres /run/postgresql
3839

3940
# look specifically for PG_VERSION, as it is expected in the DB dir
4041
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.6/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/post
5454
&& ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
5555
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample
5656

57-
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
57+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
5858

5959
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
6060
ENV PGDATA /var/lib/postgresql/data
61+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
6162
VOLUME /var/lib/postgresql/data
6263

6364
COPY docker-entrypoint.sh /

9.6/alpine/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ RUN set -ex \
5555
zlib-dev \
5656
\
5757
&& cd /usr/src/postgresql \
58+
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
59+
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
60+
&& 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 \
61+
&& grep '/var/run/postgresql' src/include/pg_config_manual.h.new \
62+
&& mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h \
5863
# configure options taken from:
5964
# https://anonscm.debian.org/cgit/pkg-postgresql/postgresql.git/tree/debian/rules?h=9.5
6065
&& ./configure \
@@ -113,10 +118,11 @@ RUN set -ex \
113118
# make the sample config easier to munge (and "correct by default")
114119
RUN sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/local/share/postgresql/postgresql.conf.sample
115120

116-
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
121+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
117122

118123
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
119124
ENV PGDATA /var/lib/postgresql/data
125+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
120126
VOLUME /var/lib/postgresql/data
121127

122128
COPY docker-entrypoint.sh /

9.6/alpine/docker-entrypoint.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ fi
2929

3030
if [ "$1" = 'postgres' ]; then
3131
mkdir -p "$PGDATA"
32-
chmod 700 "$PGDATA"
3332
chown -R postgres "$PGDATA"
33+
chmod 700 "$PGDATA"
34+
35+
mkdir -p /var/run/postgresql
36+
chown -R postgres /var/run/postgresql
37+
chmod g+s /var/run/postgresql
3438

35-
mkdir -p /run/postgresql
36-
chmod g+s /run/postgresql
37-
chown -R postgres /run/postgresql
3839

3940
# look specifically for PG_VERSION, as it is expected in the DB dir
4041
if [ ! -s "$PGDATA/PG_VERSION" ]; then

9.6/docker-entrypoint.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ fi
2929

3030
if [ "$1" = 'postgres' ]; then
3131
mkdir -p "$PGDATA"
32-
chmod 700 "$PGDATA"
3332
chown -R postgres "$PGDATA"
33+
chmod 700 "$PGDATA"
34+
35+
mkdir -p /var/run/postgresql
36+
chown -R postgres /var/run/postgresql
37+
chmod g+s /var/run/postgresql
3438

35-
mkdir -p /run/postgresql
36-
chmod g+s /run/postgresql
37-
chown -R postgres /run/postgresql
3839

3940
# look specifically for PG_VERSION, as it is expected in the DB dir
4041
if [ ! -s "$PGDATA/PG_VERSION" ]; then

Dockerfile-alpine.template

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ RUN set -ex \
5555
zlib-dev \
5656
\
5757
&& cd /usr/src/postgresql \
58+
# update "DEFAULT_PGSOCKET_DIR" to "/var/run/postgresql" (matching Debian)
59+
# see https://anonscm.debian.org/git/pkg-postgresql/postgresql.git/tree/debian/patches/51-default-sockets-in-var.patch?id=8b539fcb3e093a521c095e70bdfa76887217b89f
60+
&& 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 \
61+
&& grep '/var/run/postgresql' src/include/pg_config_manual.h.new \
62+
&& mv src/include/pg_config_manual.h.new src/include/pg_config_manual.h \
5863
# configure options taken from:
5964
# https://anonscm.debian.org/cgit/pkg-postgresql/postgresql.git/tree/debian/rules?h=9.5
6065
&& ./configure \
@@ -113,10 +118,11 @@ RUN set -ex \
113118
# make the sample config easier to munge (and "correct by default")
114119
RUN sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/local/share/postgresql/postgresql.conf.sample
115120

116-
RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql
121+
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod g+s /var/run/postgresql
117122

118123
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
119124
ENV PGDATA /var/lib/postgresql/data
125+
RUN mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA" && chmod 700 "$PGDATA"
120126
VOLUME /var/lib/postgresql/data
121127

122128
COPY docker-entrypoint.sh /

0 commit comments

Comments
 (0)