composebuilder

Docker Compose: Typesense 27.1 Search Engine

Docker Compose stack for Typesense 27.1, a fast typo-tolerant search engine, with a persistent data volume, a health endpoint and an admin API key on localhost.

When to use this stack

Typesense is an open source search engine built for instant, typo-tolerant search over structured records. It returns results quickly, supports faceting, filtering and sorting, and keeps its API simple, which makes it a good fit for product catalogs, documentation sites and internal search boxes. This stack runs Typesense 27.1 with a bootstrap admin key, a data directory on a named volume and a healthcheck against its health endpoint. It gives you a working search service in one container, with no separate database to manage.

Use this stack when a site or application needs fast search over a dataset that fits in memory and changes regularly, or when you want to replace a slow SQL LIKE query with a dedicated index. Do not use it as a general primary database, and do not expose the admin key to the browser. Typesense keeps its indexes in RAM, so plan the memory limit according to the dataset size. A single node also has no built-in failover, so take regular snapshots if the index is expensive to rebuild. The port is bound to 127.0.0.1, so public traffic should come through a proxy that handles TLS.

docker-compose.yml

services:
  typesense:
    image: typesense/typesense:27.1
    restart: unless-stopped
    environment:
      TYPESENSE_API_KEY: ${TYPESENSE_API_KEY}
      TYPESENSE_DATA_DIR: /data
    volumes:
      - typesense_data:/data
    ports:
      - "127.0.0.1:8108:8108"
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://127.0.0.1:8108/health"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 15s

volumes:
  typesense_data:

.env

.env
# Bootstrap admin key. Use it on the server only and create scoped search keys for clients.
TYPESENSE_API_KEY=CHANGE_ME_LONG_RANDOM_ADMIN_KEY

Start and verify

The admin key is loaded into the shell only for the requests below. Compose reads .env on its own. The health endpoint answers without a key, while listing collections requires the key in the X-TYPESENSE-API-KEY header.

Shell
set -a; . ./.env; set +a
docker compose config --quiet
docker compose up -d
docker compose ps
docker compose logs --tail=30 typesense
curl -s http://127.0.0.1:8108/health
curl -s -H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" http://127.0.0.1:8108/collections
curl -s -X POST http://127.0.0.1:8108/collections \
  -H "X-TYPESENSE-API-KEY: $TYPESENSE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"products","fields":[{"name":"title","type":"string"},{"name":"price","type":"float"}],"default_sorting_field":"price"}'

The first request should return {"ok":true}, the second an empty list before you create anything, and the third the new collection definition.

Production checklist

  • Replace the CHANGE_ME key with a long random value, and keep it out of frontend code and public repositories.
  • Create scoped search-only keys through the keys endpoint, restrict them to one collection, and give those keys to browsers.
  • Keep port 8108 bound to 127.0.0.1, and terminate TLS in a reverse proxy when browsers call the API directly.
  • Take snapshots through the snapshot operation endpoint on a schedule, and copy them off the server.
  • Size the memory limit with headroom above the indexed dataset, because the working set is held in RAM.
  • Rotate keys by creating a new key, deploying it, and then revoking the old one.
  • Limit request body sizes and rate at the proxy to protect the index from bulk abuse.
  • Pin the image to the 27.x line and read the upgrade notes before moving to a new minor version.

Common problems

  • Symptom: requests return 401 with a message about the API key. Cause: the X-TYPESENSE-API-KEY header is missing, or the value does not match the key in .env. Fix: send the header with the exact value from .env, or create a scoped key with the required permissions.

  • Symptom: the container exits right after startup with an error about the API key. Cause: TYPESENSE_API_KEY is empty, usually because .env is not in the same folder as docker-compose.yml. Fix: run docker compose config and check the resolved value, then correct the file location.

  • Symptom: collections are gone after docker compose down and up. Cause: the data volume was removed, or the data directory was changed. Fix: keep the named volume mounted at /data, and never use docker compose down -v on data you need.

  • Symptom: the healthcheck stays unhealthy while the logs look normal. Cause: the curl binary is missing from the image or the endpoint is not reachable inside the container. Fix: run docker compose exec typesense curl -fsS http://127.0.0.1:8108/health by hand. If curl is missing, use another health probe for your image version.

Variations

  • Three-node cluster: run three Typesense containers with separate volumes and the –nodes option, which requires an odd number of nodes for quorum.
  • HTTPS front door: add Caddy with automatic certificates, expose only ports 80 and 443, and keep 8108 private.
  • Feeding from an application: place a worker container on the same network and send batches of documents to http://typesense:8108 with a key that has write permission.

Questions

What is the difference between the admin key and a search key?

The admin key can create collections, delete data and manage other keys. A search key can only query one collection with fixed filters. Browsers and public pages should only ever receive a search key.

Why do my collections disappear after I recreate the container?

The index data lives in the directory set by TYPESENSE_DATA_DIR, which this file maps to a named volume. If the volume was removed or the mount path was changed, Typesense starts with an empty data directory.

Does Typesense need a separate queue or cache?

No. A single Typesense node stores its indexes on disk and keeps the working set in memory. Your application sends documents to it directly through the HTTP API.

Can I run Typesense with HTTPS?

The server speaks plain HTTP on port 8108. Terminate TLS in a reverse proxy such as Caddy or Nginx, and keep port 8108 bound to localhost.

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
  • ClickHouse 25.8 Analytics Database

    Docker Compose stack for ClickHouse 25.8 with a dedicated user, a healthcheck, raised file limits and HTTP and native ports on localhost for analytical queries.

    • clickhouse
    Difficulty: Advanced
  • Elasticsearch 8 + Kibana Search Stack

    Docker Compose stack for Elasticsearch 8.19 and Kibana 8.19 with security enabled, a persistent volume, a healthcheck and localhost-only ports.

    • elasticsearch
    • kibana
    Difficulty: Advanced
  • FastAPI + MongoDB 7 + Mongo Express

    Docker Compose stack for a Python FastAPI API on MongoDB 7 with authentication, a healthcheck, persistent storage and a protected Mongo Express UI on localhost.

    • api
    • mongodb
    • mongo-express
    Difficulty: Intermediate
  • MariaDB 11.4 LTS + Adminer 5

    Docker Compose stack with MariaDB 11.4 LTS, a healthcheck, a named volume and Adminer 5 on localhost. A lightweight admin UI for MySQL-compatible databases.

    • mariadb
    • adminer
    Difficulty: Beginner

Browse more Databases & Search stacks or the full library.