Skip to content

Commit fd62a29

Browse files
committed
feat: run Postgres instance with custom port and socket dir
1 parent 1c0d46f commit fd62a29

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

extended-postgres/Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ COPY --from=build-env /usr/local/bin/wal-g /usr/local/bin/wal-g
4141
ARG PG_SERVER_VERSION
4242
ENV PG_SERVER_VERSION=${PG_SERVER_VERSION:-15}
4343

44+
ARG PG_UNIX_SOCKET_DIR
45+
ENV PG_UNIX_SOCKET_DIR=${PG_UNIX_SOCKET_DIR:-"/var/run/postgresql"}
46+
47+
ARG PG_SERVER_PORT
48+
ENV PG_SERVER_PORT=${PG_SERVER_PORT:-5432}
49+
4450
ARG PG_TIMETABLE_VERSION
4551
ENV PG_TIMETABLE_VERSION=${PG_TIMETABLE_VERSION:-5.3.0}
4652
ARG SET_USER_VERSION
@@ -184,15 +190,15 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/partial \
184190
&& apt-get clean -y autoclean \
185191
&& rm -rf /var/lib/apt/lists/* \
186192
# remove standard pgdata
187-
&& rm -rf /var/lib/postgresql/${PG_SERVER_VERSION}/
193+
&& rm -rf /var/lib/postgresql/${PG_SERVER_VERSION}/
188194

189-
EXPOSE 5432
195+
EXPOSE ${PG_SERVER_PORT}
190196

191197
# Prepare Postgres start script
192198
RUN echo "#!/bin/bash" > /pg_start.sh && chmod a+x /pg_start.sh \
193-
&& echo "chown -R postgres:postgres \${PGDATA} /var/run/postgresql" \
199+
&& echo "chown -R postgres:postgres \${PGDATA} \${PG_UNIX_SOCKET_DIR}" \
194200
>> /pg_start.sh \
195-
&& printf "sudo -Eu postgres /usr/lib/postgresql/$(echo ${PG_SERVER_VERSION} | sed 's/beta.*//' | sed 's/rc.*//')/bin/postgres -D \${PGDATA} >& /proc/1/fd/1 \n" \
201+
&& printf "sudo -Eu postgres /usr/lib/postgresql/$(echo ${PG_SERVER_VERSION} | sed 's/beta.*//' | sed 's/rc.*//')/bin/postgres -D \${PGDATA} -k \${PG_UNIX_SOCKET_DIR} -p \${PG_SERVER_PORT} >& /proc/1/fd/1 \n" \
196202
>> /pg_start.sh \
197203
# Infinite sleep to allow restarting Postgres
198204
&& echo "/bin/bash -c \"trap : TERM INT; sleep infinity & wait\"" \

0 commit comments

Comments
 (0)