How to Install Meilisearch on a VPS with Docker: Fast Search for Your Own App
Search inside an app is often the part that feels slowest, even when the data is not that large. A product catalog search, a document archive, or an internal directory usually starts life as a database LIKE query — fine for a few hundred rows, strained at tens of thousands, and completely unforgiving of typos. A user types a product name with one letter swapped, gets nothing back, and concludes the item does not exist.
Meilisearch exists for that gap. It is an open source search engine that runs as a single service, takes documents through an API, indexes them, and answers searches in milliseconds — with typo tolerance, filters, and matched-word highlighting included. This guide installs it on a VPS with Docker Compose, locks it with a master key, fills one sample index, and tests real searches through the API. At the end you have a foundation that plugs into any application, not just a container that happens to be running.
Prerequisites
- A Linux VPS with Docker and Docker Compose v2 installed.
- A domain for Meilisearch if you later want to expose it behind a reverse proxy, for example
search.example.com. For the core steps in this guide, access from inside the VPS over127.0.0.1is enough. curlandjqfor testing the API (install withsudo apt install -y curl jqif missing).- One sample dataset. This guide uses a small product catalog; swap in your own data when you adopt it.
Check Docker and Compose first:
docker --version
docker compose versionExpected output: both commands print a version number with no error.
Step 1: create the folder, a master key, and the Compose file
Create a working folder at /opt/meilisearch:
sudo mkdir -p /opt/meilisearch
cd /opt/meilisearchGenerate a strong master key — at least 16 bytes, per Meilisearch's rule — and store it in a .env file:
echo "MEILI_MASTER_KEY=$(openssl rand -hex 32)" | sudo tee .env
sudo chmod 600 .envopenssl rand -hex 32 produces 64 random hexadecimal characters. The .env file gets 600 permissions so only its owner can read it, because anyone holding the master key can create and delete other API keys.
Now create compose.yml in the same folder:
sudo nano compose.ymlContents:
services:
meilisearch:
container_name: meilisearch
image: getmeili/meilisearch:latest
ports:
- "127.0.0.1:7700:7700"
volumes:
- ./meili_data:/meili_data
environment:
- MEILI_MASTER_KEY=${MEILI_MASTER_KEY}
- MEILI_ENV=production
- MEILI_NO_ANALYTICS=true
restart: unless-stoppedWhat each part does:
image: getmeili/meilisearch:latest is Meilisearch's official image on Docker Hub. If you want a version that never moves, replace latest with a specific release number.
127.0.0.1:7700:7700 maps port 7700 to localhost only. That is deliberate: the Meilisearch API is not opened to the internet. Applications that need search run on the same server, or reach it through a reverse proxy you control.
./meili_data:/meili_data stores the index database in the meili_data folder. Without this volume, every index disappears whenever the container is removed.
MEILI_ENV=production turns on production mode: a master key becomes mandatory (Meilisearch refuses to start if the key is missing or under 16 bytes) and the search preview interface is disabled.
MEILI_NO_ANALYTICS=true switches off Meilisearch's built-in telemetry.
Save the file (Ctrl+O, Enter, Ctrl+X in nano), then start the stack:
sudo docker compose up -dCheck the container and its log:
sudo docker compose ps
sudo docker compose logs --tail=30 meilisearchExpected output: the container shows as running, and the log shows a "Server listening on" line for 127.0.0.1:7700 or localhost:7700.
Step 2: check health and fetch the API keys
The health endpoint is the one route that needs no authentication. Test it:
curl http://127.0.0.1:7700/healthExpected output:
{"status":"available"}If that comes back, the engine is alive. Now list the API keys using the master key stored in .env as a Bearer token:
source .env
curl -s http://127.0.0.1:7700/keys \
-H "Authorization: Bearer $MEILI_MASTER_KEY" | jq .Expected output: the keys generated automatically from the master key, including the "Default Search API Key", the "Default Admin API Key", and the "Default Read-Only Admin API Key". Note two of them:
Default Admin API Key — for writes: adding documents, changing settings, deleting indexes. Use it from your application server only, never embed it in frontend code.
Default Search API Key — read-only: searches and document retrieval. This is the key that is safe to use from a browser or client app.
Store both keys as carefully as the master key. You can fetch them again any time through the /keys endpoint while you still hold the master key.
Step 3: create an index and send the first documents
An index in Meilisearch is a collection of searchable documents — roughly one table in a database. Create a sample data file products.json in /opt/meilisearch:
sudo nano products.jsonFill it with three sample products:
[
{ "id": 1, "title": "Airflow Running Shoes", "category": "sports", "price": 899000, "description": "Lightweight running shoes with ventilated soles for daily training." },
{ "id": 2, "title": "Mountain Trail Shoes", "category": "sports", "price": 1299000, "description": "Trail shoes with strong grip for dirt paths and rocky terrain." },
{ "id": 3, "title": "Work Backpack 20L", "category": "bags", "price": 549000, "description": "Water-resistant work backpack with a 15-inch laptop compartment." }
]Send these documents to an index called products, using the Admin API Key (replace YOUR_ADMIN_KEY with the key from step 2):
curl -s -X POST 'http://127.0.0.1:7700/indexes/products/documents' \
-H "Authorization: Bearer YOUR_ADMIN_KEY" \
-H 'Content-Type: application/json' \
--data-binary @products.json | jq .Expected output: a task object, for example:
{
"taskUid": 0,
"indexUid": "products",
"status": "enqueued",
"type": "documentAdditionOrUpdate",
"enqueuedAt": "2026-11-04T01:00:00Z"
}Notice the status: enqueued, not succeeded. Writes in Meilisearch are asynchronous — the request is accepted, queued, then processed. Do not test search before the task finishes. Check its status with the returned taskUid:
curl -s 'http://127.0.0.1:7700/tasks/0' \
-H "Authorization: Bearer YOUR_ADMIN_KEY" | jq .statusExpected output: "succeeded". If it still says "enqueued" or "processing", wait a few seconds and retry. If it says "failed", read the error field in the same task response to find the cause.
Step 4: test search, including a typo
Now test a search with the Search API Key (replace YOUR_SEARCH_KEY):
curl -s -X POST 'http://127.0.0.1:7700/indexes/products/search' \
-H "Authorization: Bearer YOUR_SEARCH_KEY" \
-H 'Content-Type: application/json' \
-d '{"q": "running shoes"}' | jq '.hits[] | {title, category, price}'Expected output: the two shoe products, with "Airflow Running Shoes" first because its title matches most strongly.
Test the typo tolerance — the reason many people pick Meilisearch:
curl -s -X POST 'http://127.0.0.1:7700/indexes/products/search' \
-H "Authorization: Bearer YOUR_SEARCH_KEY" \
-H 'Content-Type: application/json' \
-d '{"q": "runing shoes"}' | jq '.hits[] | .title'Expected output: "Airflow Running Shoes" still shows up despite the misspelled query. If a query returns zero results even though the documents exist, check first whether the indexing task from step 3 reached succeeded — searching an index that has not finished indexing comes back empty by design.
Step 5: set searchable and filterable fields
By default Meilisearch searches every field and ranks by its own relevance. For a product catalog, two settings are almost always worth adding.
First, limit the searched fields so a word in the description does not beat an exact title match:
curl -s -X PUT 'http://127.0.0.1:7700/indexes/products/settings/searchable-attributes' \
-H "Authorization: Bearer YOUR_ADMIN_KEY" \
-H 'Content-Type: application/json' \
-d '["title", "description", "category"]' | jq .taskUidSecond, register category as a filterable field so the app can narrow results to one category:
curl -s -X PUT 'http://127.0.0.1:7700/indexes/products/settings/filterable-attributes' \
-H "Authorization: Bearer YOUR_ADMIN_KEY" \
-H 'Content-Type: application/json' \
-d '["category"]' | jq .taskUidBoth commands return a task too — wait for succeeded through /tasks/{taskUid} as in step 3 before testing. Then try a filtered search:
curl -s -X POST 'http://127.0.0.1:7700/indexes/products/search' \
-H "Authorization: Bearer YOUR_SEARCH_KEY" \
-H 'Content-Type: application/json' \
-d '{"q": "shoes", "filter": "category = sports"}' | jq '.hits[] | .title'Expected output: only the sports-category products appear.
Step 6: keep port 7700 off the internet
This setup deliberately binds port 7700 to 127.0.0.1, so from outside the VPS the port does not answer. Do not change that mapping to 7700:7700 without a plan. If your app runs on another server, or you want the search dashboard reachable through a domain, put Meilisearch behind a reverse proxy with HTTPS and access rules — for example Nginx Proxy Manager — and let that proxy be the only door in from the internet. The Search API Key may be used from the frontend; the Admin API Key must not.
For updates, from /opt/meilisearch:
sudo docker compose pull
sudo docker compose up -dCheck the logs afterwards, and make sure the meili_data folder is covered by your backups: that is where the entire index lives.
Troubleshooting
curl to /health gets no answer. The container may still be starting or may have failed. Check sudo docker compose ps and sudo docker compose logs --tail=50 meilisearch. If the log mentions the master key, the problem is almost certainly in .env (see the next item).
The container stops immediately with a master key error. In production mode the master key is mandatory and must be at least 16 bytes. Make sure the .env file sits in the same folder as compose.yml, the variable is spelled exactly MEILI_MASTER_KEY, and its value is not empty. sudo docker compose config shows the rendered configuration — use it to confirm the variable is actually picked up (its value will be visible, so do not share that output).
The API answers 401 or invalid API key. Three common causes: you used the Search API Key for a write operation (writes need the Admin API Key or the master key), the token was pasted incompletely (Meilisearch keys are long and easy to truncate), or the master key changed after the container was recreated — derived keys are generated from the master key, so replacing it invalidates all old API keys.
Search returns zero results even though documents were sent. Almost always because the indexing task has not reached succeeded yet. Check with GET /tasks/{taskUid}. Another cause: the index you are searching has a different name from the one you filled — index names are case-sensitive.
The index vanishes after the container is removed and recreated. The ./meili_data:/meili_data volume is not mounted, usually because Compose was run from a different folder. Always run commands from /opt/meilisearch and confirm the meili_data folder contains a data.ms file before removing the container.
Summary table
| Component | Role | Note |
|---|---|---|
| Master key | The root key, generates all API keys | In .env, at least 16 bytes, never shared |
| Admin API Key | Writes: documents, settings, index deletion | Server side only |
| Search API Key | Reads: search and document retrieval | Safe to use from the frontend |
| products index | The collection of searchable documents | Created automatically when the first documents arrive |
| Task | Asynchronous processing queue | Check via GET /tasks/{taskUid} until succeeded |
| Port 7700 | Meilisearch HTTP API | Bound to 127.0.0.1 only, not to the internet |
Final checklist
- The meilisearch container is running and /health answers {"status":"available"}.
- The master key is stored in a 600-permission .env file and never shared.
- The Admin API Key and Search API Key are recorded from the /keys endpoint.
- The sample index is filled and its task shows succeeded.
- A plain search and a misspelled search both return the right results.
- Category filtering works after filterable-attributes is set.
- Port 7700 is unreachable from the internet (only 127.0.0.1).
- The /opt/meilisearch/meili_data folder is covered by backups.
From here, the most sensible next step is connecting Meilisearch to your real application: replace products.json with an export of your data, send document updates whenever data changes, and put the Search API Key in the frontend search box. The engine is ready; what remains is your data.
What data would you most like to make searchable — a product catalog, an article archive, or an internal directory? And does search in your app today still run as a direct database query? Tell us in the comments.
Read also: the Rnevio article "Satu VPS, Banyak Layanan: Nginx Reverse Proxy + HTTPS Let's Encrypt" explains how to publish internal services behind a domain with HTTPS, while the paired guide in this batch is available at a RustDesk guide to a self-hosted remote desktop server on a VPS.


Diskusi
Ada pertanyaan atau pengalaman yang ingin dibagikan?
Komentar ditinjau sebelum ditampilkan. Mari berdiskusi dengan sopan dan sesuai topik.
Tulis komentar