daniel1kp
daniel1kp

Reputation: 83

Is it possible to add pgvector extension on top of postgres:15.3-alpine images

I'm trying to dockerize pg-vector and I found this Dockerfile from the official repository. https://github.com/pgvector/pgvector/blob/master/Dockerfile#L2C1-L3C1

The Dockerfile currently uses postgres base image right now, I'm wondering if I can add the pgvector extension on top of the alpine images. If not, what are other possible options?

Upvotes: 8

Views: 5249

Answers (3)

Ritesh Nemade
Ritesh Nemade

Reputation: 11

Updated instructions for postgres:16.4-alpine based on above answers

FROM postgres:16.4-alpine
WORKDIR /app

RUN apk add git
RUN apk add build-base
RUN apk add clang15
RUN apk add llvm15-dev

RUN git clone --branch v0.8.0 https://github.com/pgvector/pgvector.git

WORKDIR /app/pgvector

RUN make
RUN make install

Refer for latest installation guide: https://github.com/pgvector/pgvector?tab=readme-ov-file#docker

Upvotes: 0

jdoconnor
jdoconnor

Reputation: 41

Updated instructions are below for newer alpine images based on deed02392's answer

ARG PGGDOCKERTAG=13-alpine3.17
FROM postgres:$PGGDOCKERTAG AS pgvector-builder
RUN apk add git
RUN apk add build-base
RUN apk add clang
RUN apk add llvm15-dev llvm15
WORKDIR /home
RUN git clone --branch v0.4.4 https://github.com/pgvector/pgvector.git
WORKDIR /home/pgvector
RUN make
RUN make install

FROM postgres:$PGGDOCKERTAG
COPY --from=pgvector-builder /usr/local/lib/postgresql/bitcode/vector.index.bc /usr/local/lib/postgresql/bitcode/vector.index.bc
COPY --from=pgvector-builder /usr/local/lib/postgresql/vector.so /usr/local/lib/postgresql/vector.so
COPY --from=pgvector-builder /usr/local/share/postgresql/extension /usr/local/share/postgresql/extension

Upvotes: 4

deed02392
deed02392

Reputation: 5022

This extension of the Alpine docker image worked for me:

$ cat Dockerfile
FROM postgres:14.4-alpine AS pgvector-builder
RUN apk add git
RUN apk add build-base
RUN apk add clang
RUN apk add llvm13-dev
WORKDIR /home
RUN git clone --branch v0.4.4 https://github.com/pgvector/pgvector.git
WORKDIR /home/pgvector
RUN make
RUN make install

FROM postgres:14.4-alpine
COPY --from=pgvector-builder /usr/local/lib/postgresql/bitcode/vector.index.bc /usr/local/lib/postgresql/bitcode/vector.index.bc
COPY --from=pgvector-builder /usr/local/lib/postgresql/vector.so /usr/local/lib/postgresql/vector.so
COPY --from=pgvector-builder /usr/local/share/postgresql/extension /usr/local/share/postgresql/extension

$ docker build -t postgres:14.4-alpine-pgvector .

Upvotes: 6

Related Questions