Skip to content

Instantly share code, notes, and snippets.

@ranjanprj
Forked from ItsWendell/Dockerfile
Created May 31, 2024 17:43
Show Gist options
  • Save ranjanprj/2979113f8cd14c018bedac253a3ebf23 to your computer and use it in GitHub Desktop.
Save ranjanprj/2979113f8cd14c018bedac253a3ebf23 to your computer and use it in GitHub Desktop.
Postgres Dockerfile with Custom Extensions using pgxn
## Alternatives: postgres:15-alpine
ARG BASE_IMAGE=postgis/postgis:15-3.4-alpine
## Custom Alpine Postgres docker file with custom extensions
FROM ${BASE_IMAGE} as builder
# Install required dependencies
RUN apk --no-cache add \
python3 \
py3-pip \
cmake \
make \
gcc \
g++ \
clang15 \
llvm15 \
postgresql-dev \
&& pip install pgxnclient
# Install extensions using pgxn
RUN pgxn install 'h3=4.1.3' \
&& pgxn install 'vector=0.4.4' \
&& pgxn install 'pg_uuidv7=1.3.0' \
&& pgxn install 'madlib'
## Cleanup to reduce image size
RUN apk del \
python3 \
py3-pip \
cmake \
make \
gcc \
g++ \
clang15 \
llvm15 \
postgresql-dev \
&& rm -rf /var/cache/apk/* \
&& rm -rf /root/.cache \
&& rm -rf /root/.pgxn
## Custom Alpine Postgres docker file with our extensions
FROM ${BASE_IMAGE}
## Copy all extensions from the builder stage
COPY --from=builder /usr/local/lib/postgresql/* /usr/local/lib/postgresql/
COPY --from=builder /usr/local/share/postgresql/extension/* /usr/local/share/postgresql/extension/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment