composebuilder

Docker Compose: Qdrant Vector Database with API Key

Run Qdrant 1.20 vector database in Docker Compose with API key authentication, persistent storage, loopback-only ports and a health check for semantic search.

When to use this stack

Qdrant is an open-source vector database written in Rust. You create collections of vectors with an optional payload, such as the original text or a document ID, and query them by similarity, optionally filtered by payload fields. It is commonly used as the retrieval layer for retrieval-augmented generation, for semantic search over documents and for recommendations. This stack pins Qdrant 1.20.0, enables API key authentication through the QDRANT__SERVICE__API_KEY variable, stores its segments in a named volume, and binds both the REST port and the gRPC port to 127.0.0.1 so that only processes on the host can connect.

Use this stack when you build an application that needs fast similarity search and you want the data to stay on your own server. Pair it with an embedding model, such as one served by Ollama, to create the vectors. Do not use it when a relational database with a full-text index answers your question, because adding a vector store also adds an embedding pipeline to maintain. Do not use it when you need to serve millions of vectors from a small machine without enough RAM, because the index is kept in memory for speed. Also avoid publishing the port to the internet without TLS and the API key, since the API can delete whole collections.

docker-compose.yml

services:
  qdrant:
    image: qdrant/qdrant:v1.20.0
    restart: unless-stopped
    environment:
      QDRANT__SERVICE__API_KEY: ${QDRANT_API_KEY}
    ports:
      - "127.0.0.1:6333:6333"
      - "127.0.0.1:6334:6334"
    volumes:
      - qdrant_storage:/qdrant/storage
    healthcheck:
      test: ["CMD-SHELL", "bash -c ':> /dev/tcp/127.0.0.1/6333' || exit 1"]
      interval: 15s
      timeout: 5s
      retries: 5
      start_period: 15s

volumes:
  qdrant_storage:

.env

.env
QDRANT_API_KEY=CHANGE_ME_LONG_RANDOM_API_KEY_AT_LEAST_32_CHARS

Start and verify

Shell
# 1. Generate a random API key and paste it into QDRANT_API_KEY
openssl rand -hex 32

# 2. Validate the compose file and the variable substitution
docker compose config --quiet

# 3. Start Qdrant in the background
docker compose up -d

# 4. The qdrant service should show "(healthy)" after its start period
docker compose ps

# 5. List collections with the API key (expected: a JSON response with an empty list at first)
export QDRANT_API_KEY=$(grep '^QDRANT_API_KEY=' .env | cut -d= -f2-)
curl -fsS -H "api-key: ${QDRANT_API_KEY}" http://127.0.0.1:6333/collections

# 6. The same request without the key must fail (expected: 401 or 403)
curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:6333/collections

Create a test collection with the vector size that matches your embedding model, then insert a point and search it. The vector size must be identical for every point in the same collection, so decide it before you load data.

Production checklist

  • Keep both ports bound to 127.0.0.1 and reach Qdrant from applications on the same host or the same Docker network.
  • Use an API key of at least 32 random characters, and store it in each application’s secret store rather than in source code.
  • Put any remote access behind TLS with a reverse proxy, and never send the API key over plain HTTP across the internet.
  • Back up qdrant_storage with a snapshot taken through the Qdrant snapshot API, or stop the container briefly and copy the volume.
  • Size the host memory for your vectors. Qdrant keeps indexes in memory by default, and an out-of-memory kill loses no data but interrupts service.
  • Record the embedding model name and vector size next to each collection, so that you never mix vectors from two models.
  • Pin the image tag and test upgrades on a copy of the storage volume, because storage formats can change between minor versions.
  • Keep the host firewall closed to ports 6333 and 6334.

Common problems

  • Symptom: every request returns 401 or 403 even though the key looks right. Cause: the header name is wrong or the key in the shell differs from the one in .env. Fix: send the key in the api-key header and compare the value with the file, since a trailing space or quote is easy to miss.
  • Symptom: inserting points fails with a dimension mismatch. Cause: the collection was created with a different vector size than the embedding model produces. Fix: check the embedding output length and recreate the collection with that size, then reinsert the data.
  • Symptom: the container stays unhealthy. Cause: the image has no curl or wget, so the check relies on bash and the TCP port, and the start period was too short on a slow disk. Fix: read docker compose logs qdrant, increase start_period, and remove the healthcheck if the image in use lacks bash.
  • Symptom: search results are slow after loading many vectors. Cause: the index is not built yet or the host has too little memory and is swapping. Fix: check the collection status in the API, add memory, and keep the index settings at their defaults unless you have measured a need to change them.
  • Symptom: data is missing after docker compose down -v. Cause: the named volume was deleted with the -v flag. Fix: restore from a snapshot. Avoid the -v flag unless you intend to delete the data.

Variations

  • Read-only key: Qdrant supports separate read-only API keys in newer versions. Give applications that only search a read-only key, and keep the full key for administration. Check the current documentation for the variable names of your image version.
  • Behind Caddy: add a Caddy service that proxies a domain to qdrant:6333 on the Docker network, and remove the loopback mappings. Caddy provides TLS, and applications on other machines connect over HTTPS with the API key.
  • Combined with Ollama: run an embedding model in an Ollama container on the same network, and write a small ingestion script that embeds documents and upserts them into a collection. Keep the embedding model name in the collection metadata for future reference.

Questions

What is a vector database used for?

It stores numeric embeddings of text, images or other data and finds the nearest matches to a query vector. This powers semantic search, retrieval for AI assistants and recommendation features.

Which port should my application use?

Use port 6333 for the REST API and port 6334 for gRPC. Most client libraries support both, and the REST API is the easiest to test with curl.

Why does Qdrant need an API key here?

The API key stops unauthenticated requests from reading or deleting collections. Even with the ports bound to 127.0.0.1, a key protects the data if another process or a reverse proxy exposes the port later.

Adapt this stack

Load these files into the builder to rename services, change ports, add a cache or a proxy, and generate fresh passwords for the .env.

Open in builder
  • Home Assistant Smart Home Hub

    Run Home Assistant 2026.10 in Docker Compose with a pinned image, persistent config volume, timezone setup and reverse proxy notes for secure remote access.

    • homeassistant
    Difficulty: Intermediate
  • n8n Workflow Automation with PostgreSQL

    Self-host n8n 2.48 with PostgreSQL 16 in Docker Compose: encrypted credentials, database healthcheck, loopback-only port and a production checklist.

    • postgres
    • n8n
    Difficulty: Intermediate
  • Nextcloud + MariaDB + Redis File Sync

    Self-host Nextcloud with MariaDB 11.4 and Redis in Docker Compose. Pinned tags, database healthcheck, memory cache and the production steps for HTTPS and cron.

    • nextcloud
    • db
    • redis
    Difficulty: Intermediate
  • Ollama + Open WebUI Local AI Chat

    Run local AI models with Ollama and a chat interface with Open WebUI in Docker Compose. Pinned images, a health check, loopback-only access and RAM guidance.

    • ollama
    • open-webui
    Difficulty: Beginner

Browse more Automation, AI & Self-Hosted stacks or the full library.