# How to install Umami Analytics with Docker, PostgreSQL and Caddy on a VPS | Nuvits

Source: [https://nuvits.net/en/blog/install-umami-analytics-docker-caddy-vps](https://nuvits.net/en/blog/install-umami-analytics-docker-caddy-vps)

Published 2026-12-06, by Fernando Chagas.

This tutorial installs Umami `3.5.1`, an open source alternative to Google Analytics, on an Ubuntu 24.04 VPS with Docker Compose. The data lives in a PostgreSQL `18.7` database that only Umami can reach, and the dashboard sits behind Caddy `2.11.9` with automatic HTTPS. By the end, the tracking script is on your site, a click is counted as an event, and the database backup and restore are tested. Everything was tested on December 6, 2026 in a clean Ubuntu 24.04.5 LTS container (`amd64`).

![Umami 3.5.1 dashboard for the test site showing 1 visitor, 1 visit, 1 view and a 3-second visit duration, recorded by the tracking script right after the installation](https://nuvits.net/blog/install-umami-analytics-docker-caddy-vps/umami-dashboard-test-visit.webp)

## Versions used

| Component | Version | Source |
| --- | --- | --- |
| Umami | `3.5.1` (2026-12-02) | [Umami releases](https://github.com/umami-software/umami/releases/tag/v3.5.1) |
| PostgreSQL | `18.7-alpine` | [Docker Hub](https://hub.docker.com/_/postgres) |
| Caddy | `2.11.9` (2026-11-05) | [Caddy releases](https://github.com/caddyserver/caddy/releases/tag/v2.11.9) |
| Docker Engine | `29.10.1` | official `apt` repository |
| Docker Compose | `v5.8.1` (plugin) | official `apt` repository |
| System | Ubuntu 24.04.5 LTS, `amd64` | |

The tags are pinned in the Compose file. The `docker-compose.yml` in the Umami repository uses `umami:latest` and `postgres:15-alpine`. Here both images have a fixed version, and every version change is a step you decide on, with a backup first.

## What you need

- A VPS with 64-bit Ubuntu 24.04 and a user with `sudo` (the examples use `deploy`). If the machine is brand new, start with [First security steps on an Ubuntu 24.04 VPS](https://nuvits.net/en/blog/secure-ubuntu-24-04-vps).
- Docker and the Compose plugin installed from the official repository, as in [How to install Docker and Docker Compose on Ubuntu 24.04](https://nuvits.net/en/blog/install-docker-compose-ubuntu-24-04).
- A subdomain with a DNS `A` record pointing to the VPS IPv4 address. The examples use `analytics.example.com`.
- Ports `80` and `443` free and open in the firewall, so Caddy can issue and renew the Let's Encrypt certificate. Umami's port `3000` and PostgreSQL's `5432` stay out of `ports:`, because Docker publishes ports around `ufw` (see [The Docker port is still open with ufw](https://nuvits.net/en/blog/docker-port-still-open-with-ufw)).

With the dashboard open, one site registered and a few events, the test measured about **206 MiB** of RAM for Umami, **85 MiB** for PostgreSQL and **52 MiB** for Caddy. The Umami image takes **1.37 GB** of disk once pulled. The stack fits easily on any [Docker VPS](https://nuvits.net/en/docker-vps) plan.

## 1. Create the folder and the .env file

Create the project folder:

```bash
mkdir -p ~/umami && cd ~/umami
```

Generate the `.env` file with the domain and three random secrets. Replace `analytics.example.com` with your subdomain:

```bash
cat > .env <<EOF
UMAMI_DOMAIN=analytics.example.com
POSTGRES_PASSWORD=$(openssl rand -hex 24)
APP_SECRET=$(openssl rand -hex 32)
TWO_FACTOR_ENCRYPTION_KEY=$(openssl rand -hex 32)
EOF
chmod 600 .env
```

- `POSTGRES_PASSWORD` is the database password. It goes into Umami's `DATABASE_URL`, which is why the value is hexadecimal: only letters and digits, nothing that needs escaping in a URL.
- `APP_SECRET` signs logins and is part of how anonymous session IDs are computed. It has been required since 3.5.0, and Umami rejects an empty value or the placeholder. Changing it later signs everyone out and makes returning visitors count as new.
- `TWO_FACTOR_ENCRYPTION_KEY` encrypts the two-factor authentication secrets. Without it, no user can turn on 2FA.

All three are described on the [Umami environment variables](https://umami.is/docs/environment-variables) page.

> **Keep a copy of .env off the VPS.** The database backup is useless without the PostgreSQL password, and a different `APP_SECRET` after a restore signs users out. Store a copy of the file in a password manager.

## 2. Create the Caddyfile and docker-compose.yml

Create the `Caddyfile`. Caddy requests the Let's Encrypt certificate, redirects HTTP to HTTPS and compresses responses:

```caddy Caddyfile
{$UMAMI_DOMAIN} {
	encode zstd gzip
	reverse_proxy umami:3000
}
```

Create `docker-compose.yml`. Only `caddy` declares `ports:`. PostgreSQL sits on a `backend` network marked `internal`, which only Umami can reach:

```yaml docker-compose.yml
name: umami

services:
  db:
    image: postgres:18.7-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: umami
      POSTGRES_USER: umami
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
    volumes:
      - umami_db:/var/lib/postgresql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U umami -d umami"]
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - backend

  umami:
    image: ghcr.io/umami-software/umami:3.5.1
    restart: unless-stopped
    init: true
    environment:
      DATABASE_URL: postgresql://umami:${POSTGRES_PASSWORD}@db:5432/umami
      APP_SECRET: ${APP_SECRET:?set APP_SECRET in .env}
      TWO_FACTOR_ENCRYPTION_KEY: ${TWO_FACTOR_ENCRYPTION_KEY:?set TWO_FACTOR_ENCRYPTION_KEY in .env}
      DISABLE_TELEMETRY: "1"
    depends_on:
      db:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://localhost:3000/api/heartbeat || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 30s
    networks:
      - backend
      - proxy

  caddy:
    image: caddy:2.11.9
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    environment:
      UMAMI_DOMAIN: ${UMAMI_DOMAIN:?set UMAMI_DOMAIN in .env}
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      umami:
        condition: service_healthy
    networks:
      - proxy

networks:
  backend:
    internal: true
  proxy:

volumes:
  umami_db:
  caddy_data:
  caddy_config:
```

> **With PostgreSQL 18, the volume goes in `/var/lib/postgresql`.** Starting with 18, the official image stores data in `/var/lib/postgresql/18/docker`. With the volume mounted at `/var/lib/postgresql/data`, as in older examples and in the Umami repository's Compose file, the container does not start, and the log begins with `Error: in 18+, these Docker images are configured to store database data in a format which is compatible with "pg_ctlcluster"`.

`DISABLE_TELEMETRY` turns off the anonymous telemetry Umami sends. The `healthcheck` uses the `/api/heartbeat` route, and Caddy only starts after Umami answers. That way it does not return 502 while Umami is still applying migrations.

## 3. Validate and start

Validate both files before starting:

```bash
cd ~/umami
docker compose config -q && echo CONFIG_OK
docker run --rm --env-file .env -v "$PWD/Caddyfile:/etc/caddy/Caddyfile:ro" caddy:2.11.9 caddy validate --config /etc/caddy/Caddyfile
```

The first command prints `CONFIG_OK`, and the second ends with `Valid configuration`. Start the stack:

```bash
docker compose up -d
docker compose ps
```

In the test, with the images already pulled, `up -d` took about 30 seconds, because Caddy waits for Umami to become `healthy`. `docker compose ps` showed `db` and `umami` as `(healthy)`, `umami` with only `3000/tcp` (an internal port, not mapped to the host) and `caddy` with `0.0.0.0:80->80/tcp` and `0.0.0.0:443->443/tcp`.

On the first start, Umami creates its tables. Check the end of the log:

```bash
docker compose logs umami | tail -n 6
```

```text
All migrations have been successfully applied.

✓ Database is up to date.
▲ Next.js 16.4.6
- Local:         http://localhost:3000
- Network:       http://0.0.0.0:3000
```

Check that only Caddy's ports are listening on the host:

```bash
sudo ss -tulpn | grep -E ':(80|443|3000|5432)\b'
```

Only `docker-proxy` shows up, on ports `80` and `443`. Test the redirect and the health route:

```bash
curl -sSI http://analytics.example.com/ | head -n 3
curl -fsS https://analytics.example.com/api/heartbeat
```

The expected answers are `HTTP/1.1 308 Permanent Redirect`, with `Location: https://analytics.example.com/`, and `{"ok":true}`. If HTTPS fails or returns 502, [Fix Caddy 502 Bad Gateway and HTTPS errors with Docker](https://nuvits.net/en/blog/fix-caddy-docker-502-bad-gateway-https-vps) covers DNS, ports and service names.

## 4. Change the admin password

Umami starts with the user `admin` and the password `umami`. As long as that password works, anyone who opens the subdomain gets into the dashboard. Do this right after `up -d`:

1. Open `https://analytics.example.com` and sign in with `admin` and `umami`.
2. Click the `admin` user, open **Settings** and go to **Security**.
3. Click **Change password**, enter the current password (`umami`) and a strong one, stored in a password manager.

In the test, after the change, signing in with `admin` and `umami` returned `401`. On the same screen, **Enable 2FA** turns on two-factor authentication, which works because `.env` already has `TWO_FACTOR_ENCRYPTION_KEY`.

## 5. Add the site and install the tracking script

In the top menu, open **Websites** and click **Add website**. Enter a name and the site's domain (for example, `site.example.com`) and save. Open the site from the list, click **Edit** and copy the code in the **Tracking code** section. It looks like this, with your site's `data-website-id`:

```html
<script defer src="https://analytics.example.com/script.js" data-website-id="8e277acc-992b-4805-86e4-15bdc1893989"></script>
```

Paste the line inside the `<head>` of every page. On a site with templates, it goes in the shared layout; on a static site, in each HTML file. `defer` keeps the script from delaying page rendering.

To count clicks, add `data-umami-event` to the element. The value becomes the event name in the dashboard:

```html
<button data-umami-event="cta-contratar">Contratar</button>
```

In the test, the site's page, opened in Chrome with a desktop browser User-Agent, loaded `script.js` and sent two `POST` requests to `/api/send`: a page view on load and an event on the button click. The dashboard then showed 1 visitor and 1 view, as in the image at the top, and the **Events** tab listed `cta-contratar` once. The Umami API returned the same counts:

```json
{"pageviews":1,"visitors":1,"visits":1,"bounces":0,"totaltime":3}
```

> **Headless browser visits are not counted.** Umami drops bot traffic. In the test, the same page opened in headless Chrome, with its default User-Agent, got `200` from `/api/send`, and nothing reached the database. To check the installation, open the site in your everyday browser.

If your site sets a Content Security Policy, add `https://analytics.example.com` to `script-src`, so `script.js` loads, and to `connect-src`, for the `/api/send` calls. Without it, the browser blocks tracking.

## 6. Back up and restore the database

The database is what needs a backup. Caddy issues certificates again on its own, and Umami keeps no data outside PostgreSQL. `pg_dump` in custom format runs while the service is up:

```bash
mkdir -p ~/backups
cd ~/umami
docker compose exec -T db pg_dump -U umami -d umami --format=custom > ~/backups/umami-$(date +%F).dump
ls -lh ~/backups
```

To run it every day at 03:15 and keep 14 days, add this line to the `deploy` user's `crontab -e`:

```text
15 3 * * * cd /home/deploy/umami && docker compose exec -T db pg_dump -U umami -d umami --format=custom > /home/deploy/backups/umami-$(date +\%F).dump && find /home/deploy/backups -name 'umami-*.dump' -mtime +14 -delete
```

In a `crontab`, `%` needs a `\` in front, as in `date +\%F`. Copy the files off the VPS too, because a backup that only lives on the same disk is lost with it. [VPS backup with Restic](https://nuvits.net/en/blog/vps-backup-restic) covers copying to S3 storage.

To restore, stop Umami, recreate the database and load the file:

```bash
cd ~/umami
docker compose stop umami
docker compose exec -T db psql -U umami -d postgres -c 'DROP DATABASE umami WITH (FORCE);' -c 'CREATE DATABASE umami OWNER umami;'
docker compose exec -T db pg_restore -U umami -d umami --no-owner < ~/backups/umami-YYYY-MM-DD.dump
docker compose start umami
```

Replace `YYYY-MM-DD` with the file's date. In the test, the restore brought back the two events recorded before (the page view and the click), and Umami was `healthy` again in 20 seconds, with the same login.

## 7. Update Umami

Before each update, read the release notes in the [Umami releases](https://github.com/umami-software/umami/releases) and take a backup. Then change the tag in `docker-compose.yml` and recreate only that service:

```bash
cd ~/umami
docker compose exec -T db pg_dump -U umami -d umami --format=custom > ~/backups/umami-before-update.dump
sed -i 's#umami:3.5.1#umami:NEW_VERSION#' docker-compose.yml
docker compose pull umami
docker compose up -d umami
docker compose logs umami | tail -n 5
```

Replace `NEW_VERSION` with the new version number, without the `v` of the release tag. Umami applies database migrations on startup. In the test, a fresh `3.5.0` installation updated to `3.5.1` was `healthy` again in 15 seconds, and the log showed `No pending migrations to apply.` and `✓ Database is up to date.`. Moving PostgreSQL to another major version (from 18 to 19, for example) does not work by changing the tag alone: it requires `pg_dump` and a restore into a new volume.

## Common problems

- **The dashboard shows zero visits:** open the site in a regular browser without an ad blocker, and check the DevTools Network tab for `script.js` and `/api/send`. If they are missing, the script is not in the `<head>` of the published page. If they are blocked, the cause is the CSP or a blocker.
- **Caddy returns 502 right after `up -d`:** Umami is not `healthy` yet. Check `docker compose ps` and `docker compose logs umami`.
- **The database fails with `in 18+, these Docker images are configured...`:** the volume is mounted at `/var/lib/postgresql/data`. Use `/var/lib/postgresql`, as in the Compose file above.
- **Umami does not start and complains about `APP_SECRET`:** the variable is empty or still the placeholder. Generate a new one with `openssl rand -hex 32`.
- **Returning visitors counted as new:** `APP_SECRET` changed. Restore the value you saved with `.env`.

## What the test did not cover

The test ran in an isolated Ubuntu 24.04.5 LTS container without a public IP, with Docker installed from the official repository and started by hand, because the container has no systemd. DNS propagation, public certificate issuance by Let's Encrypt, `ufw` and HTTP/3 traffic were left out. Instead of a public certificate, Caddy used `tls internal` with the same `reverse_proxy umami:3000`. The test site was a static page served by the same Caddy and opened in Chrome with a desktop browser User-Agent. The memory figures come from that environment and are an order of magnitude.

## Next steps

- To get an alert when the site or Umami itself goes down, see [How to install Uptime Kuma with Docker Compose and Caddy on a VPS](https://nuvits.net/en/blog/install-uptime-kuma-docker-caddy-vps).
- To manage the VPS Docker stacks from a web interface, see [How to install Portainer with Docker and Caddy on a VPS](https://nuvits.net/en/blog/install-portainer-docker-caddy-vps).
- To pick the machine, see [Docker VPS](https://nuvits.net/en/docker-vps), [Linux VPS](https://nuvits.net/en/linux-vps) and the [VPS plans](https://nuvits.net/en/vps).
