A lightweight Docker image providing PostgreSQL 17 with the pgvector extension on Alpine Linux. This image is ideal for applications requiring vector similarity search capabilities alongside traditional relational database features.
This Docker image packages PostgreSQL 17 with the pgvector extension, enabling efficient vector operations and similarity searches directly within your database. Built on Alpine Linux for minimal footprint and fast startup times.
Key Features:
- PostgreSQL 17 with pgvector extension pre-installed
- Alpine Linux base for minimal image size
- Pre-configured for external connections
- Optimized for vector similarity search operations
- Ready-to-use with sensible defaults
docker pull ghcr.io/your-username/postgres17-pgvector:latestdocker run -d \
--name postgres-vector \
-e POSTGRES_PASSWORD=yourpassword \
-p 5432:5432 \
ghcr.io/your-username/postgres17-pgvector:latestgit clone <your-repo-url>
cd postgres17-pgvector
docker build -t postgres17-pgvector .docker run -d \
--name my-postgres \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=myapp \
-e POSTGRES_USER=myuser \
-p 5432:5432 \
postgres17-pgvectordocker run -d \
--name my-postgres \
-e POSTGRES_PASSWORD=secret \
-p 5432:5432 \
-v postgres_data:/var/lib/postgresql/data \
postgres17-pgvectorversion: '3.8'
services:
postgres:
image: postgres17-pgvector
environment:
POSTGRES_PASSWORD: secret
POSTGRES_DB: myapp
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:POSTGRES_PASSWORD- Required: Password for the PostgreSQL superuserPOSTGRES_USER- Optional: PostgreSQL superuser (default:postgres)POSTGRES_DB- Optional: Default database (default: same asPOSTGRES_USER)
- Listens on all interfaces (
listen_addresses = '*') - Accepts connections from any host with password authentication
- Unix socket directory:
/var/lib/postgresql - Encoding: UTF8
- Locale: C
Once your container is running, enable the pgvector extension in your database:
-- Connect to your database
psql -h localhost -U postgres -d your_database
-- Enable the vector extension
CREATE EXTENSION vector;
-- Create a table with a vector column
CREATE TABLE items (
id BIGSERIAL PRIMARY KEY,
embedding VECTOR(1536)
);
-- Insert vectors
INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');
-- Perform similarity search
SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;-- Euclidean distance (L2)
SELECT * FROM items ORDER BY embedding <-> '[1,2,3]' LIMIT 10;
-- Inner product
SELECT * FROM items ORDER BY embedding <#> '[1,2,3]' LIMIT 10;
-- Cosine distance
SELECT * FROM items ORDER BY embedding <=> '[1,2,3]' LIMIT 10;-- Create HNSW index for faster similarity search
CREATE INDEX ON items USING hnsw (embedding vector_l2_ops);
-- Or IVFFlat index
CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100);# Connect from host
psql -h localhost -U postgres
# Connect from within container
docker exec -it postgres-vector psql -U postgresdocker logs postgres-vector# Backup
docker exec postgres-vector pg_dump -U postgres mydb > backup.sql
# Restore
cat backup.sql | docker exec -i postgres-vector psql -U postgres- PostgreSQL 17: Latest stable PostgreSQL version
- pgvector: Official Alpine package for vector operations
- Alpine Linux: Lightweight base image from edge repository
- su-exec: For proper process privilege handling
- 5432: PostgreSQL default port
/var/lib/postgresql/data: PostgreSQL data directory
git clone <repository>
cd postgres17-pgvector
docker build -t postgres17-pgvector .# Test basic functionality
docker run --rm -e POSTGRES_PASSWORD=test postgres17-pgvector pg_isready -U postgres
# Test pgvector extension
docker run --rm -e POSTGRES_PASSWORD=test postgres17-pgvector psql -U postgres -c "CREATE EXTENSION vector;"Connection refused:
- Ensure PostgreSQL has fully started (wait 5-10 seconds after container start)
- Check if port 5432 is available on the host
Authentication failed:
- Verify
POSTGRES_PASSWORDenvironment variable is set - Check pg_hba.conf configuration
Extension not found:
- Confirm you're using the correct database
- Check if pgvector package installed correctly
[Add your license information here]
[Add contribution guidelines here]
Note: This image uses Alpine Edge repository which may contain less stable packages. For production use, consider using a tagged Alpine version or the official PostgreSQL image with pgvector added.