I wanted a way to add the ankane/pgvector PostgreSQL extension to the DDEV postgres service. I created a .ddev/db-build/Dockerfile file and added the code from https://github.com/pgvector/pgvector/blob/v0.5.1/Dockerfile (except the FROM), but had errors during building the container (make does not work). Maybe someone has an example or a hint?
DDEV: How can I add the pgvector extension to the postgres container?
468 Views Asked by Weri At
2
There are 2 best solutions below
0
On
An other way is to create an additional docker compose yaml in the .ddev directory. This way we can use the ankane/pgvector image:
Example of the docker-compose.pgvector.yaml file:
services:
pgsql:
image: 'ankane/pgvector:latest'
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
environment:
PGPASSWORD: 'db'
POSTGRES_DB: 'db'
POSTGRES_USER: 'db'
POSTGRES_PASSWORD: 'db'
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
volumes:
- ".:/mnt/ddev_config"
- 'pgsql:/var/lib/postgresql/data'
healthcheck:
test:
- CMD
- pg_isready
- '-q'
- '-d'
- 'db'
- '-U'
- 'db'
retries: 3
timeout: 5s
volumes:
pgsql:

The main problem was, that I had to install the
build-essentialpackage. Addeddbimage_extra_packages: [build-essential]in the config.yaml.And on the image you can see my Docker configuration to have pgvector in place:
Content of the Dockerfile.vector:
For more information about the customization of Docker images look here: https://ddev.readthedocs.io/en/latest/users/extend/customizing-images/#adding-extra-dockerfiles-for-webimage-and-dbimage