Installing SurrealDB on a VPS: Docker, TLS, persistent storage, and automatic backups
TL;DR
In this guide, we will deploy SurrealDB 2.x on Ubuntu Server 24.04 via Docker Compose, connect persistent storage, protect the database behind Caddy with automatic TLS, configure a firewall, and set up daily backups to S3 using Restic.
- SurrealDB will run in a separate container with a pinned image version.
- Data will be stored on the VPS disk rather than inside an ephemeral Docker container.
- Only HTTPS port 443 will remain public; SurrealDB port 8000 will be accessible locally only.
- Caddy will automatically obtain and renew the Let’s Encrypt TLS certificate.
- A logical database export and a configuration backup will be created daily.
- Before an upgrade, you can run a check, perform a manual export, and roll the container back to the previous version.
1. TL;DR
This section already contains a brief deployment plan. If you are working with a VPS for the first time, run the commands sequentially: first prepare the operating system, then install Docker, create the project directory, configure the environment variables, start the containers, and only connect DNS to the server after verification.
2. Contents
This article is intended for a VPS owner who wants to run SurrealDB independently for a SaaS application, internal service, prototype, or small production project. The configuration is not tied to a specific framework: the database can be accessed via the HTTP API, WebSocket, or the official SDK.
For production, it is important to understand the limitations of this example. A single VPS with one database instance is not a highly available cluster. TLS, a firewall, and backups protect against common operational errors, but they do not replace a backup server, monitoring, and regular data recovery testing.
3. What we are configuring and why
What is SurrealDB
SurrealDB is a multimodel database supporting document, graph, and relational approaches. It provides its own SQL-like SurrealQL language, HTTP API, WebSocket connections, and an authentication mechanism. This is convenient when an application needs documents, relationships between entities, and queries across multiple data models without a separate set of specialized services.
This guide uses the SurrealDB 2.x branch. The specific image tag must be pinned rather than using latest. An unpredictable update can change query syntax, the export format, or transaction behavior when the container restarts.
Final installation architecture
Two Docker Compose containers will run on the server:
surrealdb— the database server, listening for HTTP and WebSocket connections on the internal Docker network address;caddy— the reverse proxy, accepting HTTPS requests and forwarding them to SurrealDB.
Port 8000 will not be exposed to the public internet. Caddy will connect to SurrealDB using the service name surrealdb:8000. Database data will be stored in the /srv/surrealdb/data directory, which is mounted into the container. The Compose configuration, .env file, Caddyfile, and database export will be stored separately from the Docker layers.
What you will have after following the instructions
After configuration, you will have an address such as https://db.example.com. Through it, the application will be able to make API requests to SurrealDB. The server will obtain a TLS certificate automatically, and Caddy will renew it without manually running Certbot.
A command for manual verification will also be available:
curl -fsS https://db.example.com/health
When operating correctly, SurrealDB will respond with a successful HTTP status. For administrative operations, use separate credentials and do not pass the password in the URL, shell history, or application source code.
Self-hosted or managed service
| Criterion | SurrealDB on your own VPS | Managed service |
|---|---|---|
| Control | Full control over the OS, network, versions, and data location | Part of the infrastructure is hidden and managed by the provider |
| Cost | Fixed cost of the VPS and separate backup storage | Payment depends on the plan, operations, traffic, and data volume |
| Maintenance | Updates, monitoring, and recovery are handled independently | Some tasks are handled by the service operator |
| Flexibility | You can change network rules, the proxy, and the file structure | Only the provided APIs and settings are available |
A self-hosted option is reasonable if the data must be stored at a selected location, a predictable budget is needed, or full control over the environment is required. A managed solution may be better for a team without administration experience, for critical systems requiring high availability, or when there is no time to test recovery independently.
Limitations of a single server
A single VPS has a single point of failure: a disk, hypervisor, network connectivity problem, or an administrator’s erroneous command can temporarily make the database unavailable. A backup in the same directory will not protect against losing the entire server, so backups must be sent to external S3-compatible storage or a separate server.
Do not expose SurrealDB directly to the internet without TLS and network restrictions. Even with built-in authentication, an open port increases the attack surface and makes access control more difficult.
4. What VPS configuration is needed for this task
Minimum configuration
For development, testing, and a small database, a VPS with two virtual CPUs, 4 GB of RAM, and a fast SSD with at least 40 GB of capacity will be sufficient. For production, leave room for the file cache, Docker, the reverse proxy, backups, and background application processes.
| Scenario | CPU | RAM | Disk | Network |
|---|---|---|---|---|
| Local development and demo | 2 vCPU | 2–4 GB | 40 GB NVMe SSD | 100 Mbps |
| Small production | 2–4 vCPU | 4–8 GB | 80–160 GB NVMe SSD | 100–1000 Mbps |
| Medium load | 4–8 vCPU | 16–32 GB | 200+ GB NVMe SSD | 1 Gbps |
As a practical starting option, you can get a VPS with 4 vCPUs, 8 GB of RAM, at least 100 GB of NVMe SSD storage, a public IPv4 address, and a 1 Gbps port. This capacity will allow you to run the database itself, Caddy, a small backend, and a monitoring service without pushing memory to its limit.
How to estimate disk space
Disk size must include more than just the current data volume. Leave at least 30–40 percent of free space for temporary files, fragmentation, updates, and exports. For example, if the database occupies 35 GB, a 40 GB disk is too small: exports, logs, and new records can quickly fill the filesystem.
A logical export may temporarily occupy an amount of space comparable to the database size. If you plan to keep several local copies, increase the disk size or send each copy immediately to external storage.
When a dedicated server is needed
A dedicated server makes sense if the database constantly uses substantial CPU or RAM, works with tens or hundreds of gigabytes of data, handles a high request rate, or must provide predictable performance without interference from neighboring virtual machines. A dedicated server is also convenient for a large node, analytics, and multiple services that cannot be split across different VPS instances.
For one small SurrealDB instance, a dedicated server is usually excessive. First measure the actual load: average and peak CPU usage, disk latency, number of connections, database size, and request frequency. Moving to a dedicated server without metrics often only increases costs without fixing incorrect indexes or slow queries.
Choosing a location
Place the VPS closer to your users and application. If the backend and SurrealDB are in the same location, latency between them will be lower than when connecting across several regions. For personal data, also consider legal requirements, customer agreements, and data storage rules.
Check whether the provider supplies a public IPv4 address or only IPv6. For automatic TLS, the domain must resolve to the server, and incoming TCP ports 80 and 443 must be accessible from the internet. If only IPv6 is used, make sure that clients actually support this route.
5. Server Preparation
Initial Conditions
The example is designed for a fresh Ubuntu Server 24.04 LTS with a user having temporary SSH access. Work as a regular user with sudo, not as root. Replace admin, the IP address, and the domain with your own values.
From the local computer, create a key if you do not already have one:
ssh-keygen -t ed25519 -C "admin@vps"
Copy the public key to the server:
ssh-copy-id admin@SERVER_IP
Verify key-based login in a new terminal. Do not close the current SSH session until you have confirmed that the new login method works.
Updates and Basic Packages
Connect to the server and update the package index:
sudo apt update
sudo apt full-upgrade -y
Install utilities for diagnostics, firewall management, SSH protection, and working with repositories:
sudo apt install -y \
ca-certificates \
curl \
gnupg \
lsb-release \
git \
jq \
unzip \
htop \
ncdu \
ufw \
fail2ban \
restic
Reboot the server if the kernel was updated:
sudo reboot
User and sudo
If the user has not yet been created, run the command as root or an existing administrator:
sudo adduser deploy
sudo usermod -aG sudo deploy
sudo install -d -m 700 -o deploy -g deploy /home/deploy/.ssh
sudo cp /home/admin/.ssh/authorized_keys /home/deploy/.ssh/authorized_keys
sudo chown deploy:deploy /home/deploy/.ssh/authorized_keys
sudo chmod 600 /home/deploy/.ssh/authorized_keys
Verify the login:
ssh deploy@SERVER_IP
SSH Configuration
Create a separate SSH drop-in file so that the main configuration is not modified:
sudo tee /etc/ssh/sshd_config.d/ hardening.conf >/dev/null <<'EOF'
There must be no space in the path name above. Use the correct command:
sudo tee /etc/ssh/sshd_config.d/hardening.conf >/dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
EOF
sudo sshd -t
sudo systemctl reload ssh
Before disabling passwords, make sure key-based login has already been tested. If you lose the only working key and disable password authentication, you will need the provider's console or rescue mode.
UFW Firewall
Allow SSH, HTTP, and HTTPS. Do not open port 8000: it will only be needed inside the Docker network.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verbose
If SSH runs on a non-standard port, replace the 22/tcp rule with the actual port. When using IPv6, verify that the UFW rules are also applied to IPv6.
Fail2ban
Create a local jail configuration for SSH:
sudo tee /etc/fail2ban/jail.d/sshd.local >/dev/null <<'EOF'
[sshd]
enabled = true
port = 22
backend = systemd
maxretry = 5
findtime = 10m
bantime = 1h
EOF
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
Fail2ban does not replace keys, a firewall, or updates. It only temporarily blocks IP addresses from which repeated failed login attempts are observed.
6. Software Installation — Step by Step
Step 1. Installing Docker Engine and Compose Plugin
For Ubuntu, you can use the official Docker installation script. In production, it is preferable to connect the official apt repository and pin package versions, but for the first deployment, the script reduces the number of manual steps.
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sudo sh /tmp/get-docker.sh
rm /tmp/get-docker.sh
Add the current user to the Docker group:
sudo usermod -aG docker "$USER"
newgrp docker
Check the versions:
docker --version
docker compose version
docker run --rm hello-world
In 2026, use the current Docker Engine and Compose v2, but for reproducibility, pin the SurrealDB image version in the Compose file. The Docker group effectively grants privileges close to root, so do not add unnecessary users to it.
Step 2. Creating the Directory Structure
Create a separate application directory, a data directory, and a directory for local exports:
sudo mkdir -p /srv/surrealdb/{data,backups,caddy/data,caddy/config}
sudo chown -R "$USER":"$USER" /srv/surrealdb
cd /srv/surrealdb
Do not delete the data directory when reinstalling the containers. This is where SurrealDB's persistent data is stored.
Step 3. Creating the Secrets File
The .env file will be read by Docker Compose. The password must be long, random, and unique to this database. Do not add the file to Git.
DB_ROOT_PASSWORD="$(openssl rand -base64 32 | tr -dc 'A-Za-z0-9_@%+=' | head -c 32)"
printf 'SURREAL_ROOT_USER=root\nSURREAL_ROOT_PASSWORD=%s\n' "$DB_ROOT_PASSWORD" > /srv/surrealdb/.env
chmod 600 /srv/surrealdb/.env
cat /srv/surrealdb/.env
Save the password in a secrets manager. The cat command is shown only for the initial check and should not be executed while recording the terminal or sharing the screen.
Step 4. Creating Docker Compose
The example below uses the surrealdb/surrealdb:v2.6.0 image. Before installation, check that the required stable tag is available in the registry and choose a version tested with your application. Do not replace the tag with latest.
cat > /srv/surrealdb/compose.yml <<'EOF'
services:
surrealdb:
image: surrealdb/surrealdb:v2.6.0
container_name: surrealdb
restart: unless-stopped
command:
- start
- --log
- info
- --user
- ${SURREAL_ROOT_USER}
- --pass
- ${SURREAL_ROOT_PASSWORD}
- rocksdb:/data/database.db
environment:
TZ: UTC
volumes:
- ./data:/data
expose:
- "8000"
healthcheck:
test: ["CMD", "/surreal", "isready", "--endpoint", "http://127.0.0.1:8000"]
interval: 30s
timeout: 5s
retries: 5
start_period: 20s
networks:
- surrealnet
caddy:
image: caddy:2.10-alpine
container_name: surrealdb-caddy
restart: unless-stopped
depends_on:
surrealdb:
condition: service_healthy
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- ./caddy/data:/data
- ./caddy/config:/config
networks:
- surrealnet
networks:
surrealnet:
driver: bridge
EOF
The start command starts the server, while the rocksdb:/data/database.db path instructs SurrealDB to use a RocksDB file inside the persistent directory. Do not mount the same file simultaneously in multiple database instances.
Step 5. Starting and Checking the Containers
Before starting, check the final variable interpolation and Compose syntax:
cd /srv/surrealdb
docker compose --env-file .env config
Start the services in the background:
docker compose --env-file .env up -d surrealdb
View the status and logs:
docker compose ps
docker compose logs --tail=100 surrealdb
At this stage, Caddy is not configured yet, so first check the internal endpoint:
curl -fsS http://127.0.0.1:8000/health || true
docker inspect --format='{{json .State.Health}}' surrealdb | jq
If the container has stopped, do not restart it endlessly in a loop. First examine the logs: the most common causes are an incorrect environment variable, a busy port, a corrupted data directory, or an error in the startup parameters.
Step 6. Checking the Image Version
Make sure that the container is running the expected image:
docker inspect --format='{{.Config.Image}}' surrealdb
docker exec surrealdb /surreal version
In production, record the selected tag in the project's change log. If the application depends on specific SurrealQL capabilities, create a test scenario for migrations and queries before updating.
7. Configuration
DNS and domain name
Let the database be available at db.example.com. Create an A record pointing to the VPS IPv4 address. If you use IPv6, add an AAAA record only after checking routing and the firewall.
You can check DNS from the server itself:
getent hosts db.example.com
dig +short A db.example.com
dig +short AAAA db.example.com
Do not start automatic TLS until DNS begins returning the correct address. Let’s Encrypt must be able to connect to port 80 or 443 from outside.
Caddyfile for TLS and reverse proxy
Create the file /srv/surrealdb/Caddyfile. Replace the domain and contact email with your own values:
cat > /srv/surrealdb/Caddyfile <<'EOF'
{
email [email protected]
}
db.example.com {
encode zstd gzip
reverse_proxy surrealdb:8000 {
health_uri /health
health_interval 30s
health_timeout 5s
}
log {
output file /data/access.log
format json
}
header {
Strict-Transport-Security "max-age=31536000"
X-Content-Type-Options "nosniff"
Referrer-Policy "no-referrer"
}
}
EOF
chmod 644 /srv/surrealdb/Caddyfile
Caddy obtains the certificate, stores it in the caddy/data directory, and renews it automatically. This directory must also be included in backups: without it, Caddy will be able to obtain the certificate again, but local ACME state data and configuration history will be lost.
Starting Caddy
After configuring DNS, start the reverse proxy:
cd /srv/surrealdb
docker compose --env-file .env up -d
docker compose ps
docker compose logs --tail=100 caddy
The logs should contain a message indicating successful certificate issuance or that the certificate already exists. If Caddy cannot obtain a certificate, check DNS, UFW, the provider’s security group, and whether another process is using ports 80 or 443.
Checking HTTPS
Check TLS and the health endpoint:
curl -I https://db.example.com
curl -fsS https://db.example.com/health
openssl s_client -connect db.example.com:443 -servername db.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates
Expect an HTTP response without a certificate error and certificate validity dates corresponding to the current period. Perform the check from an external computer, not only from the VPS itself: a local check may not detect routing or DNS issues.
Checking authentication
For the administrative API, use the password from the local secrets file. Do not pass it on the command line if this causes it to appear in history or the process list. The specific endpoint and request format depend on the SurrealDB version and the SDK in use, so compare the example with the documentation for the installed release.
Perform the minimum server availability check without passing a secret:
curl -fsS https://db.example.com/health
Then execute a test request from a temporary application script or the official CLI, passing credentials through environment variables. After checking, delete the test records or use a separate database and namespace.
Checking persistent storage
Make sure the data directory is mounted:
docker inspect surrealdb --format '{{range .Mounts}}{{println .Source " -> " .Destination}}{{end}}'
sudo du -sh /srv/surrealdb/data
sudo find /srv/surrealdb/data -maxdepth 2 -type f -ls | head
To verify persistence across a restart, create a test record, restart the container, and read it again. Do this in a test namespace if the database is already being used by the application.
docker compose restart surrealdb
docker compose ps
docker compose logs --tail=50 surrealdb
Configuring resource limits
If other services are running on the VPS, set reasonable limits for the container. Do not set the memory limit below the actual working set: if memory is insufficient, the process may be terminated by the OOM-killer.
services:
surrealdb:
deploy:
resources:
limits:
cpus: "4.0"
memory: 6G
reservations:
cpus: "1.0"
memory: 2G
In standard Docker Compose, the deploy field is not supported identically in all modes. Check the result with docker inspect before applying it. Most importantly, leave the operating system at least 1–2 GB of RAM and monitor swap, disk latency, and OOM events.
8. Backups and maintenance
What needs to be saved
A backup should include the database data, Compose configuration, Caddyfile, the Caddy directory with ACME state, and the environment variables file. The password from .env must not be published in plain text, so the Restic repository must be encrypted and the Restic password stored separately.
/srv/surrealdb/data— persistent database files;/srv/surrealdb/compose.yml— container definitions;/srv/surrealdb/Caddyfile— reverse proxy and TLS settings;/srv/surrealdb/caddy/dataandcaddy/config— Caddy state;- SurrealDB logical export — a recovery layer independent of the file format.
Do not rely solely on copying the live database directory. For a file-based database, data consistency must be taken into account. A logical export performed by the server itself is generally easier to migrate between versions and storage systems.
Preparing S3 and Restic
Create a separate S3 bucket with restricted permissions: only write and read access to backup objects, without access to other buckets. Set the Restic variables in a file accessible only to root:
sudo install -m 600 /dev/null /root/restic.env
sudo tee /root/restic.env >/dev/null <<'EOF'
export AWS_ACCESS_KEY_ID='REPLACE_ME'
export AWS_SECRET_ACCESS_KEY='REPLACE_ME'
export RESTIC_REPOSITORY='s3:https://s3.example.net/my-surrealdb-backups'
export RESTIC_PASSWORD='REPLACE_WITH_LONG_RESTIC_PASSWORD'
EOF
Do not store this file in a public Git repository. If a standard secret manager is available, it is better to load the keys from there when the cron job runs.
Daily backup script
Create a directory for temporary exports and a script:
sudo mkdir -p /var/lib/surrealdb-backup
sudo tee /usr/local/sbin/backup-surrealdb >/dev/null <<'EOF'
#!/usr/bin/env bash
set -Eeuo pipefail
PROJECT_DIR="/srv/surrealdb"
BACKUP_DIR="/var/lib/surrealdb-backup"
STAMP="$(date -u +%Y-%m-%dT%H-%M-%SZ)"
EXPORT_FILE="${BACKUP_DIR}/surrealdb-${STAMP}.surql"
source /root/restic.env
mkdir -p "$BACKUP_DIR"
cd "$PROJECT_DIR"
docker compose --env-file .env ps --status running surrealdb | grep -q surrealdb
docker exec surrealdb /surreal export \
--endpoint http://127.0.0.1:8000 \
--user "$SURREAL_ROOT_USER" \
--pass "$SURREAL_ROOT_PASSWORD" \
"$EXPORT_FILE"
restic backup \
"$EXPORT_FILE" \
"$PROJECT_DIR/compose.yml" \
"$PROJECT_DIR/Caddyfile" \
"$PROJECT_DIR/.env" \
"$PROJECT_DIR/caddy"
restic forget \
--keep-daily 7 \
--keep-weekly 4 \
--keep-monthly 6 \
--prune
rm -f "$EXPORT_FILE"
echo "Backup completed: $STAMP"
EOF
sudo chmod 700 /usr/local/sbin/backup-surrealdb
In some CLI versions, export parameters may differ. Run docker exec surrealdb /surreal export --help and adapt the command to the installed release. If the CLI cannot write the file to a path inside the container, use a temporary directory with a separate volume or output the export to stdout with redirection to the host.
Initializing the repository and test run
Initialize the encrypted Restic repository:
sudo bash -c 'source /root/restic.env && restic init'
sudo /usr/local/sbin/backup-surrealdb
Check the snapshot list:
sudo bash -c 'source /root/restic.env && restic snapshots'
sudo bash -c 'source /root/restic.env && restic check'
The restic check command checks the repository structure but does not prove that the application can restore the database. At least once a month, perform a full test restoration in a separate temporary directory or on a test VPS.
Cron scheduler
Create a daily job running, for example, at 03:15 UTC:
sudo tee /etc/cron.d/surrealdb-backup >/dev/null <<'EOF'
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
15 3 root /usr/local/sbin/backup-surrealdb >> /var/log/surrealdb-backup.log 2>&1
EOF
sudo chmod 644 /etc/cron.d/surrealdb-backup
sudo systemctl restart cron
Configure failure notifications. A simple option is to send the status to an external healthcheck service at the end of the script; a more reliable option is to use monitoring that checks when the latest Restic snapshot appeared and the repository size.
Restoring an export
First, download the required snapshot to a separate directory:
sudo mkdir -p /var/lib/surrealdb-restore
sudo bash -c 'source /root/restic.env && restic restore latest --target /var/lib/surrealdb-restore'
sudo find /var/lib/surrealdb-restore -type f -name '.surql' -ls
Do not import data over the only production database without a maintenance window and a tested plan. Start a temporary container in a separate directory, import the export, and check the number of records and the application’s main queries. Only then plan the production restoration.
Updating SurrealDB
Updates should be performed during a maintenance window:
- check the release notes and SurrealQL compatibility;
- create a manual export;
- check for a recent Restic snapshot;
- change only the image tag in
compose.yml; - start the container and check the health endpoint;
- run application smoke tests.
cd /srv/surrealdb
sudo /usr/local/sbin/backup-surrealdb
docker compose pull surrealdb
docker compose up -d surrealdb
docker compose ps
docker compose logs --tail=100 surrealdb
curl -fsS https://db.example.com/health
For a single-instance database, this is not a rolling update: there will be a brief interruption. A rolling setup requires compatible versions, a separate instance, carefully designed replication, and client behavior testing. Do not try to achieve a seamless update by simply starting a second container on the same data directory.
Monitoring
Monitor free space, memory, container restarts, log errors, and disk latency:
df -h
free -h
docker stats --no-stream
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
sudo journalctl -u docker --since "1 hour ago"
sudo dmesg -T | grep -i -E 'oom|killed process|ext4|nvme' || true
Disk space alerts should be enabled at 70–80 percent usage rather than waiting for 100 percent. When the disk is full, the database may stop writing transactions, while Caddy and Docker may be unable to create logs and temporary files.
9. Troubleshooting and FAQ
Why does the SurrealDB container terminate immediately?
First, run docker compose logs --tail=200 surrealdb and check the final configuration with docker compose config. Common causes include an incorrect variable name, an error in the start parameters, an inaccessible data directory, or an incompatible image tag. Also check docker exec surrealdb /surreal version if the container starts successfully. Do not delete the data directory before determining the cause.
Why does Caddy fail to obtain a TLS certificate?
Make sure the domain's DNS record points to this VPS and that ports 80 and 443 are allowed both in UFW and in the external security group. Run curl -I http://db.example.com from another network and check docker compose logs caddy. If Nginx or Apache is already running on the port, stop it or move the service. Also verify that the email address is correct and that there is no temporary ACME rate limit.
I get a timeout when connecting to the database
Make sure the container is healthy: docker compose ps and docker inspect surrealdb. Then check Caddy's availability with curl -v https://db.example.com/health. Port 8000 is intentionally not published externally, so a direct connection to SERVER_IP:8000 should not work. If requests from Caddy do not pass through, check the surrealdb service name and the shared Docker network in Compose.
What is the minimum suitable VPS configuration?
For development, 2 vCPUs, 2–4 GB of RAM, and at least 40 GB of SSD storage are sufficient. For a small production system, it is safer to start with 2–4 vCPUs, 8 GB of RAM, and 80–100 GB or more of NVMe storage. The assessment should be based on the database size, number of concurrent clients, query complexity, and the size of the application running on the same server. Keep at least 30 percent of the disk free and do not store the only backup on the same VPS.
Which should I choose—VPS or dedicated for this task?
A VPS is suitable for most small and medium-sized installations: it is cheaper, scales quickly, and provides sufficient CPU, RAM, and SSD resources. A dedicated server is justified for consistently high loads, large data volumes, requirements for stable performance, or when several resource-intensive services will run on the server. Make the decision based on metrics rather than the presumed prestige of the hardware: first measure CPU, RAM, I/O, and query latency.
The data disappeared after recreating the container. What was done incorrectly?
Most likely, the container was started without a bind mount or volume, or the /srv/surrealdb/data directory was deleted. Check the volumes section in Compose and the output of docker inspect surrealdb. The docker compose down -v command can delete named volumes, so do not use it without understanding the consequences. If the data is genuinely lost, restore the latest logical export or Restic snapshot to a test instance.
How do I change the root password?
Do not edit the password only in .env until you understand exactly how the current version of SurrealDB applies startup parameters. First, create a fresh backup and study the supported procedure for changing the account for your version. After changing the secret, update .env, restart the container, and verify the application's connection. Remove the old password from shell history, temporary files, and monitoring systems.
Can I open port 8000 for connections from the application?
If the application is on the same VPS, connect it to the Docker network at http://surrealdb:8000. If the backend runs on another server, it is safer to use HTTPS through Caddy, a private network, or a VPN rather than expose port 8000 to the entire internet. If necessary, restrict the firewall to the application's specific IP address and still use authentication. A public endpoint must have TLS and monitoring of login attempts.
Why is the backup not being created?
Run the script manually and review the complete output. Check access to S3, the endpoint configuration, the presence of the variables from /root/restic.env, and the available space in /var/lib/surrealdb-backup. Then run restic snapshots and restic check. Separately check the export command through docker exec: CLI changes between versions may require a different order or different argument names. Always specify absolute paths in cron.
10. Conclusions and Next Steps
As a result, SurrealDB runs in Docker on a VPS with persistent storage, HTTPS through Caddy, a closed internal port, and a daily encrypted backup to S3. The configuration remains reproducible: it can be transferred to a new server, the data can be restored, and the image version can be pinned.
Next, add external monitoring of the health endpoint and backup freshness, regularly test restoration, and optimize indexes based on real queries. As the load grows, separate the application, database, and backup systems onto dedicated resources, and before moving to multiple instances, first verify replication compatibility and the migration procedure.