add docker file

This commit is contained in:
oliviamn 2025-05-15 10:17:33 +08:00
parent 598617025f
commit 1c2dfc30d7
2 changed files with 43 additions and 0 deletions

7
.env Normal file
View File

@ -0,0 +1,7 @@
# typesense-project/.env
# Choose a strong, random string for your Admin API Key
TYPESENSE_ADMIN_API_KEY=imdiowenxodjioqwenlj
# You can also specify the Typesense version here if you want to pin it
TYPESENSE_VERSION=28.0

36
docker-compose.yml Normal file
View File

@ -0,0 +1,36 @@
# typesense-project/docker-compose.yml
version: '3.8'
services:
typesense:
image: typesense/typesense:${TYPESENSE_VERSION:-latest} # Uses TYPESENSE_VERSION from .env, defaults to latest
container_name: typesense_server
restart: unless-stopped
ports:
- "8108:8108" # Expose Typesense API port
volumes:
- ./typesense-data:/data # Persist Typesense data on the host machine
# The /data directory inside the container is where Typesense stores its data
environment:
# Pass the API key from the .env file to the container
# The Typesense container will pick this up via the --api-key command-line argument
TYPESENSE_API_KEY_FILE: /etc/typesense/typesense-api-key # Path inside container
# If you prefer to pass it directly as an env var (less secure if env vars are logged):
TYPESENSE_API_KEY: ${TYPESENSE_ADMIN_API_KEY}
# Command to start Typesense
# It needs to know where the data directory is and what the API key is.
command: '--data-dir /data --api-key=${TYPESENSE_ADMIN_API_KEY} --enable-cors'
# The --enable-cors flag is useful for local development when your frontend
# (e.g., on localhost:3000 or localhost:8000) talks to Typesense on localhost:8108
# Optional: Healthcheck to ensure Typesense is ready
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8108/health"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s # Give it some time to start up initially
networks:
default: # Default network, services can reach each other by service name