# Self-Hosted Langfuse in Docker: Install, Upgrade, Back Up

> Langfuse v4 in Docker Compose: secrets, localhost-only ports, a trace ingestion check, a backup of every volume, the 4.78 → 4.88 upgrade, rollback and restore.
> Author: Roman Belov · Published: 2026-11-01 · Source: https://futurecraft.pro/blog/langfuse-self-hosted/

Self-hosted Langfuse is a platform for tracing and evaluating LLM applications on your own server. Version v4 runs in Docker Compose as seven services, and the data sits in four stores at once. The steps, in order:

1. Take the compose file and images from one exact tag and generate secrets.
2. Close the ports with an override file: nothing should be reachable from outside.
3. Start web and worker, then wait for a health check that includes the database.
4. Send a test trace and find it in ClickHouse.
5. Take a cold backup of all volumes together with `.env`, before the first upgrade.

**What was tested and what wasn't.** The test ran on November 29, 2026 on a Linux server (8 vCPU, 23 GB, Docker 29.2.1, Compose 5.0.2), one run each: the compose file from tag v4.88.0, images 4.78.0 and 4.88.0, all external ports closed, the AI Gateway not started. It covered startup, ingestion, a Redis outage, backup, upgrade, rollback, restore and damaged secrets. The files below were rewritten for a permanent install and have not been run in this form: bash and YAML syntax and consistency with the compose file were checked. The UI, SSO, HTTPS, migration from v3 and operation under load were not tested.

For what traces are, how to connect the Python SDK and how prompt versions work, see the [step-by-step Langfuse guide](https://futurecraft.pro/blog/langfuse-step-by-step/). This article covers operations only.

## What Langfuse v4 consists of

Components are from the [documentation](https://langfuse.com/self-hosting) and the v4.88.0 compose file, image sizes from the test:

| Service | What it does | Image | On disk |
|---|---|---|---|
| langfuse-web | UI, API, trace ingestion | `langfuse:4.88.0` | 1.04 GB |
| langfuse-worker | queue processing | `langfuse-worker:4.88.0` | 803 MB |
| clickhouse | traces, observations, scores | `clickhouse-server:26.3.62.3` | 1.19 GB |
| postgres | users, projects, keys, prompts | `postgres:17` | 671 MB |
| minio | raw events, media, exports | `chainguard/minio`, no tag | 236 MB |
| redis | queue and cache | `redis:7` | not recorded |
| langfuse-ai-gateway | proxy to providers, beta | `ai-gateway:4.88.0` | not started |

The storage tags differ in strictness: ClickHouse is pinned to a patch, Postgres and Redis to a major version, and MinIO isn't pinned at all. Running `docker compose pull` without service names may update it along with the rest, so the commands below pull only web and worker.

Compose is [meant](https://langfuse.com/self-hosting/deployment/docker-compose) for local use and a single test VM. For production the documentation points to Kubernetes or a cloud.

## How much memory you need: 2.4 GiB vs 16

| Container | Idle memory, 4.78.0 |
|---|---|
| web | 1.32 GiB |
| worker | 685 MiB |
| ClickHouse | 283 MiB |
| Postgres | 80 MiB |
| MinIO | 58 MiB |
| Redis | 5 MiB |
| Total | about 2.4 GiB |

After 10,000 spans the stack grew to 2.6 GiB. For the same setup the documentation asks for 4 cores, 16 GiB and 100 GiB of disk, and the [scaling page](https://langfuse.com/self-hosting/configuration/scaling) separately allots 4 GiB to web, 4 to worker and 8 to ClickHouse.

The gap doesn't mean the documentation overstates the requirements. The test had one project, short synthetic spans and nobody opening the UI. ClickHouse uses memory for part merges and queries over long periods, the worker for evaluations and exports, and none of that was running. What the test does show is that a small machine is enough to get to know the interface. Size a production server from the documented requirements and watch `docker stats` on your own data.

## Step 1. Compose file and secrets

The script downloads the file for the chosen tag and creates `.env`. It is based on the [documentation](https://langfuse.com/self-hosting/deployment/docker-compose), with pinned versions and [headless initialization](https://langfuse.com/self-hosting/administration/headless-initialization) added:

```bash
#!/usr/bin/env bash
# init.sh - run once in an empty directory
set -euo pipefail
umask 077
TAG=4.88.0
[ ! -e .env ] || { echo ".env already exists, exiting" >&2; exit 1; }
curl -fsSLo docker-compose.yml \
  "https://raw.githubusercontent.com/langfuse/langfuse/v$TAG/docker-compose.yml"
r() { openssl rand -hex "$1"; }
PG=$(r 16); MINIO=$(r 16)
cat > .env <<ENV
COMPOSE_PROJECT_NAME=langfuse
LANGFUSE_IMAGE_TAG=$TAG
POSTGRES_VERSION=17
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=$(r 32)
SALT=$(r 32)
ENCRYPTION_KEY=$(r 32)
POSTGRES_PASSWORD=$PG
DATABASE_URL=postgresql://postgres:$PG@postgres:5432/postgres
CLICKHOUSE_PASSWORD=$(r 16)
REDIS_AUTH=$(r 16)
MINIO_ROOT_PASSWORD=$MINIO
LANGFUSE_S3_EVENT_UPLOAD_SECRET_ACCESS_KEY=$MINIO
LANGFUSE_S3_MEDIA_UPLOAD_SECRET_ACCESS_KEY=$MINIO
LANGFUSE_S3_BATCH_EXPORT_SECRET_ACCESS_KEY=$MINIO
TELEMETRY_ENABLED=false
AUTH_DISABLE_SIGNUP=true
LANGFUSE_INIT_ORG_ID=main
LANGFUSE_INIT_PROJECT_ID=app
LANGFUSE_INIT_PROJECT_PUBLIC_KEY=pk-lf-$(r 16)
LANGFUSE_INIT_PROJECT_SECRET_KEY=sk-lf-$(r 16)
LANGFUSE_INIT_USER_EMAIL=admin@example.com
LANGFUSE_INIT_USER_PASSWORD=$(r 16)
ENV
```

What is easy to break here:

- **Paired values.** The Postgres password is repeated in `DATABASE_URL`, and the three S3 keys must match `MINIO_ROOT_PASSWORD`.
- **`SALT`.** It's used to [hash API keys](https://langfuse.com/self-hosting/configuration/encryption). In the test, after the value changed, the same request got a 401.
- **`ENCRYPTION_KEY`.** Exactly 64 hex characters. With a short key web didn't start: "ENCRYPTION_KEY must be 256 bits, 64 string characters in hex format". This key encrypts saved LLM provider keys, so if you lose it you'll have to enter them again (a conclusion from the documentation, not tested).
- **Quotes.** The documentation asks not to put `LANGFUSE_INIT_*` values in double quotes.
- **Restarting with different passwords.** The volumes remember the old ones. The documentation suggests `docker compose down -v`, but that erases the data.

`TELEMETRY_ENABLED=false` turns off [aggregated telemetry](https://langfuse.com/self-hosting/security/telemetry). Replace the email with your own. The author didn't create a user in the test: there, initialization set up the organization, the project and the keys.

## Step 2. Override: all ports on localhost

The compose file publishes ports 3000, 9090 and 3031 on all interfaces. ufw won't help: the documentation warns that such firewalls don't filter ports published by Docker. Compose picks up `docker-compose.override.yml` automatically:

```yaml
services:
  langfuse-web:
    ports: !override
      - "127.0.0.1:3000:3000"
    environment:
      AUTH_DISABLE_SIGNUP: ${AUTH_DISABLE_SIGNUP:-false}
  minio:
    ports: !override
      - "127.0.0.1:9090:9000"
  langfuse-ai-gateway:
    ports: !reset []
  postgres:
    ports: !reset []
  clickhouse:
    ports: !reset []
  redis:
    ports: !reset []
```

The tags are required. Without them Compose [appends port lists](https://docs.docker.com/reference/compose-file/merge/), and `0.0.0.0` stays next to the new line. `!reset []` worked in the test on all seven services; `!override` is taken from the Compose documentation. Worker port 3030 is already bound to `127.0.0.1` in the original file.

The `environment` block is there for a different reason: the v4.88.0 compose file has no `AUTH_DISABLE_SIGNUP` variable, so without the block the line in `.env` silently does nothing. Disabled sign-up [also applies to invited people](https://langfuse.com/self-hosting/security/authentication-and-sso) who don't have an account yet.

## Step 3. Start and first login

```bash
set -euo pipefail
docker compose config -q
docker compose pull langfuse-web langfuse-worker
docker compose up -d langfuse-web langfuse-worker
curl -fsS --retry 60 --retry-delay 5 --retry-all-errors --max-time 5 \
  'http://127.0.0.1:3000/api/public/health?failIfDatabaseUnavailable=true'
docker compose ps
ss -ltn | grep -E ':(3000|3030|3031|9090|9091|5432|6379|8123|9000)\b'
```

The stores start on their own through `depends_on`, and the AI Gateway won't start. In the output of the last line, expect only `127.0.0.1`. In the test with empty volumes, health responded after 34 s and the images took 24 s to download; the documentation promises 2-3 minutes.

The `failIfDatabaseUnavailable` parameter matters: plain `/api/public/health` [checks only the API](https://langfuse.com/self-hosting/configuration/health-readiness-endpoints) and returns OK while the database is down. The page promises nothing about Redis in either case.

Open the UI through an SSH tunnel (`ssh -L 3000:127.0.0.1:3000 server`) and log in as the user from `.env`. For team access, put an HTTPS proxy in front of port 3000 and change `NEXTAUTH_URL` to the public address: it must match what the browser opens. The browser uploads media directly to MinIO, so you'll also need an external `LANGFUSE_S3_MEDIA_UPLOAD_ENDPOINT`.

## Step 4. Check ingestion all the way to the database

Web [puts events in S3 and a reference to them in the queue](https://langfuse.com/self-hosting); the worker writes them to ClickHouse. A 200 response is therefore not enough, and the check has to look for the row in the database:

```bash
#!/usr/bin/env bash
# smoke.sh
set -euo pipefail
v() { sed -n "s/^$1=//p" .env; }
curl -fsS --retry 60 --retry-delay 5 --retry-all-errors --max-time 5 \
  'http://127.0.0.1:3000/api/public/health?failIfDatabaseUnavailable=true'
N="smoke-$(openssl rand -hex 4)"; NOW=$(date +%s)
BODY=$(printf '{"resourceSpans":[{"resource":{"attributes":[]},"scopeSpans":[{"scope":{"name":"smoke"},"spans":[{"traceId":"%s","spanId":"%s","name":"%s","kind":1,"startTimeUnixNano":"%s000000000","endTimeUnixNano":"%s000000000"}]}]}]}' \
  "$(openssl rand -hex 16)" "$(openssl rand -hex 8)" "$N" "$NOW" "$NOW")
printf 'user = "%s:%s"\n' "$(v LANGFUSE_INIT_PROJECT_PUBLIC_KEY)" \
    "$(v LANGFUSE_INIT_PROJECT_SECRET_KEY)" |
  curl -sS --max-time 10 -K - -o /dev/null -w 'HTTP %{http_code}\n' \
    -H 'content-type: application/json' -H 'x-langfuse-ingestion-version: 4' \
    --data "$BODY" http://127.0.0.1:3000/api/public/otel/v1/traces
sleep 40
# shellcheck disable=SC2016
docker compose exec -T clickhouse sh -c 'clickhouse-client --user "$CLICKHOUSE_USER" \
  --password "$CLICKHOUSE_PASSWORD" --param_n="$1" \
  -q "SELECT count() FROM events_core WHERE name = {n:String}"' _ "$N"
```

The script waits for health first, then should print `HTTP 200` and `1`. The key goes through stdin so it doesn't show up in the process list. The `x-langfuse-ingestion-version: 4` header is needed for real-time display: without it, OpenTelemetry data [can lag by up to 10 minutes](https://langfuse.com/integrations/native/opentelemetry).

In the test, 10,000 spans in batches of 100 went out in 2.6 s, all accepted. After 40 s, `events_core` and `events_full` each held 10,100 rows, including a hundred test spans. The `observations` table stayed empty because v4 writes to `events_*`. Old monitoring scripts that count rows in `observations` will show zero on a new install. A wrong key got a 401.

## If Redis goes down, requests hang

With Redis stopped, ingestion returned neither 500 nor 503. Two sends in a row waited until the client timeout fired, 601 s in total, and those events never appeared in the database. After Redis started, the next sends went through without restarting web.

What this means for the application:

- **A timeout in every client.** The test sent requests with Node `fetch` and no timeout, hence the minutes of waiting. The Python SDK [defaults to 5 s](https://github.com/langfuse/langfuse-python/blob/main/langfuse/_client/environment_variables.py) (`LANGFUSE_TIMEOUT`), and OpenTelemetry exporters to 10 s per the [specification](https://opentelemetry.io/docs/specs/otel/protocol/exporter/). Set a timeout explicitly in custom senders.
- **Tracing outside the user response path.** Synchronous sending without a timeout will stall the application itself.
- **A separate check.** Run `smoke.sh` on a schedule: health may stay green during such a failure. The documentation also [describes](https://langfuse.com/self-hosting/configuration/health-readiness-endpoints) `?failIfQueueConsumptionStuck=true` on the worker; it was not tested.

## Step 5. Cold backup of all volumes

The [backups page](https://langfuse.com/self-hosting/configuration/backups) describes the stores separately, says nothing about Redis or restore order, and its `pg_dump` example uses the `langfuse` user, which doesn't exist in the official compose file: the user there is `postgres`. On a single machine it's simpler to stop the stack and copy all volumes at once, so the stores are consistent with each other.

```bash
#!/usr/bin/env bash
# backup.sh
set -euo pipefail
umask 077
TAG=$(sed -n 's/^LANGFUSE_IMAGE_TAG=//p' .env)
B="$PWD/backup/$(date +%Y%m%d-%H%M%S)-$TAG"
mkdir -p "$B"
cp .env docker-compose.yml docker-compose.override.yml "$B/"
docker compose images > "$B/images.txt"
trap 'docker compose up -d langfuse-web langfuse-worker' EXIT
docker compose stop langfuse-web langfuse-worker
docker compose exec -T postgres pg_dump -U postgres -Fc postgres > "$B/pg.dump"
docker compose stop
for v in $(docker volume ls -q --filter label=com.docker.compose.project=langfuse); do
  docker run --rm --network none -v "$v":/d:ro -v "$B":/b docker.io/postgres:17 \
    tar --numeric-owner -C /d -czf "/b/$v.tgz" .
done
(cd "$B" && sha256sum -- *.tgz pg.dump > SHA256SUMS)
echo "$B"
```

`trap` brings the stack back up even if copying fails. In the test the same procedure (with a different helper image) took 12 s for 10,100 events:

| What | Size |
|---|---|
| ClickHouse | 26.6 MB |
| Postgres, volume | 7.6 MB |
| Postgres, `pg_dump -Fc` | 395 KB |
| MinIO | 258 KB |
| Redis | 9 KB |

`pg_dump` here is insurance against a damaged volume. The author didn't try restoring Postgres alone next to a newer ClickHouse. The copy contains `.env` with every secret, so keep it in encrypted storage off the server.

## Step 6. Upgrade 4.78.0 → 4.88.0

Releases come out almost daily: between 4.78.0 (November 10) and 4.88.0 (November 26) there were 16 days and 10 minor versions. The documentation suggests tracking the `4` tag. The tag here is exact, so you know what to return to; that is this article's position, not the vendor's.

```bash
set -euo pipefail
./backup.sh
NEW=4.88.0
curl -fsSLo docker-compose.new.yml \
  "https://raw.githubusercontent.com/langfuse/langfuse/v$NEW/docker-compose.yml"
diff docker-compose.yml docker-compose.new.yml || true   # read it yourself
mv docker-compose.new.yml docker-compose.yml
sed -i "s/^LANGFUSE_IMAGE_TAG=.*/LANGFUSE_IMAGE_TAG=$NEW/" .env
docker compose pull langfuse-web langfuse-worker
docker compose up -d langfuse-web langfuse-worker
./smoke.sh
docker compose logs langfuse-web | grep -i migrat | tail -4
```

Web runs fast migrations at startup, and the worker runs long ones in the background: click the version in the UI and open Background Migrations to see their status. It's [better to start](https://langfuse.com/self-hosting/upgrade/background-migrations) the next upgrade after they finish. In the test the new version responded after 25 s, migrations were applied, the 10,100 events were still there, and another hundred were accepted.

## Rollback: three products, three behaviors

The author tried the same thing, putting the old tag back on an upgraded database, on three self-hosted products:

| | Langfuse | Open WebUI | n8n |
|---|---|---|---|
| Rollback | 4.88.0 → 4.78.0 | 0.13.5 → 0.12.5 | 2.49.8 → 2.40.0 |
| Database | Postgres + ClickHouse | SQLite | SQLite |
| Old tag on the new schema | web in a restart loop, worker running | doesn't start | starts silently in 12 s |
| What you see | "no migration found for version 61" | "Can't locate revision identified by '5e7a2c9d4b13'" | no schema errors |
| Restoring the backup | health in 23 s, 10,100 events | starts, old token accepted | starts, credentials readable |

The Langfuse log during rollback:

```text
474 migrations found in prisma/migrations
No pending migrations to apply.
error: no migration found for version 61: read down for version 61 .: file does not exist
Applying clickhouse migrations failed. Common causes:
  1. The database is unavailable or unreachable.
  2. CLICKHOUSE_PASSWORD contains special characters that are not URL-encoded.
```

This log has two traps. The hints at the end point to the password and the network, although the cause is the schema. The second trap is in the first two lines: the old image knows 474 Postgres migrations and tag 4.88.0 has [504](https://github.com/langfuse/langfuse/tree/v4.88.0/packages/shared/prisma/migrations), but Prisma didn't object to the extra thirty. Only ClickHouse stopped the startup.

Judging by the repository, the last ClickHouse migration is number 56 in tags 4.78.0-4.83.0, 59 in 4.84.0 and 61 in 4.85.0-4.88.0. So between 4.85.0 and 4.88.0 this check won't fire, and an old image may start on a newer Postgres schema as quietly as n8n does. This is a conclusion from the code; no such pair was run.

The failed rollback didn't damage the data: ClickHouse still had 10,200 events. The author didn't try going back to tag 4.88.0 afterwards and restored the copy right away.

## Restoring from a backup

First run `backup.sh` on the new version too: events after the old copy will be lost. In the test that is how the hundred events sent on 4.88.0 disappeared.

```bash
set -euo pipefail
B="$PWD/backup/20261129-120000-4.78.0"
(cd "$B" && sha256sum -c SHA256SUMS)   # before deleting anything
docker compose down                    # without -v
cp "$B/.env" "$B/docker-compose.yml" "$B/docker-compose.override.yml" .
for f in "$B"/langfuse_*.tgz; do
  v=$(basename "$f" .tgz)
  docker volume inspect "$v" > /dev/null
  docker run --rm --network none -v "$v":/d -v "$B":/b:ro docker.io/postgres:17 \
    sh -c 'find /d -mindepth 1 -delete && tar --numeric-owner -C /d -xzf "/b/$1.tgz"' _ "$v"
done
docker compose up -d langfuse-web langfuse-worker
./smoke.sh
```

The loop wipes each volume before unpacking, so the checksums come first. Volume order doesn't matter: the stack is stopped and all copies were taken at one point. Moving to another server was not tested.

## If you're on v3

Security patches for v3 continue until January 31, 2027. The move to v4 is described in the [official guide](https://langfuse.com/self-hosting/upgrade/upgrade-guides/upgrade-v3-to-v4); the author hasn't done it. The main points from there:

- ClickHouse 25.12 or newer, Postgres from 15, Redis from 7.0.
- First the latest v3 and all background migrations: `SELECT name FROM background_migrations WHERE finished_at IS NULL;` must return zero rows, otherwise v4 permanently deletes what hasn't been transferred.
- Back up Postgres and ClickHouse right before the upgrade. Simply switching the image back doesn't work; you can return the schema with `migrate ... goto 37` while the `legacy` or `dual` write mode is on.
- Automatic history transfer needs about three times the current ClickHouse volume on disk.

## SDKs, ingestion and license

Python SDK v5 and JS/TS SDK v6 [require server 4.59.0 or newer](https://langfuse.com/self-hosting/upgrade/versioning); Python SDK v4 works from 3.63.0. Current versions as of November 29, 2026: `langfuse` 5.2.0 (Python 3.11+) and `@langfuse/client` 6.1.1. OTLP is accepted over HTTP in JSON and protobuf; gRPC isn't supported.

Code outside the `ee/` directories is [MIT-licensed](https://github.com/langfuse/langfuse/blob/main/LICENSE), copyright ClickHouse, Inc. The `LANGFUSE_EE_LICENSE_KEY` key [unlocks](https://langfuse.com/self-hosting/license-key) data retention policies, audit logs, project-level roles, protected prompt labels, server-side masking, SCIM and the Instance Management API. Without it traces are [kept indefinitely](https://langfuse.com/docs/administration/data-retention), so watch the disk yourself.

## Security

As of November 29, 2026, the [repository](https://github.com/langfuse/langfuse/security/advisories) lists four published advisories: three medium and one low, the newest from April 17. All are fixed in the v3 branch (the last one in 3.167.0); they say nothing separate about v4.

The minimum for a server: ports on `127.0.0.1`, sign-up disabled, HTTPS on the proxy, `.env` with mode 600, Docker log rotation (`json-file` doesn't rotate by default) and disk space monitoring. Mask personal data [before sending it](https://futurecraft.pro/blog/llm-observability-langfuse/): server-side masking is available only with a key.

## Common errors

| Symptom | Cause | What to do |
|---|---|---|
| "no migration found for version N" | old image on a new schema | return the new tag or restore the backup |
| 401 on working keys | `SALT` changed | restore the previous `.env` |
| "ENCRYPTION_KEY must be 256 bits" | not 64 hex characters | `openssl rand -hex 32`, but only on an empty install |
| A send hangs without a response | Redis unavailable | client timeout, `docker compose logs redis` |
| HTTP 200, empty UI | queue not processed or the version header is missing | worker logs, the `x-langfuse-ingestion-version: 4` header |
| Sign-up is open although `.env` forbids it | the compose file doesn't pass the variable | the `environment` block in the override |
| "JavaScript heap out of memory" | Node heap too small | [`NODE_OPTIONS=--max-old-space-size`](https://langfuse.com/faq/all/self-hosting-javascript-heap-out-of-memory) |
| Media doesn't upload | the browser can't reach MinIO | `LANGFUSE_S3_MEDIA_UPLOAD_ENDPOINT` |

The first four rows come from the test, the rest from the documentation and the compose file.

## What to do on the first day

Bring up the stack, run `smoke.sh`, take a backup and restore it right away on the same empty install, while there's nothing to lose. Then connect the application: [first traces and prompts](https://futurecraft.pro/blog/langfuse-step-by-step/), [agent tool tracing](https://futurecraft.pro/blog/langfuse-agent-tool-tracing/). If four stores look expensive just for traces, price the cloud version or a lighter tool.
