VPS Tutorials
Odoo 19 on a VPS: private Docker, HTTPS and recovery
Deploy Odoo 19 Community with private PostgreSQL, Caddy and WebSockets. Fix image-user file permissions, replace defaults and back up the database and filestore in one recovery window.

Odoo combines business applications such as CRM, sales, purchasing, inventory, projects and websites. Available accounting and advanced features depend on edition and modules. Hosting Odoo 19 Community yourself gives control of custom modules and release timing, while making your team responsible for PostgreSQL, HTTPS, mail, storage, security and recovery.
This single-VPS layout keeps database and Odoo ports inside Docker networks, restricts database management, and backs up the database together with its filestore. It is a starting architecture, not high availability.
| Option | Main benefit | Cost or limitation | Suitable use |
|---|---|---|---|
| Odoo Online | Little server maintenance | Restricted custom modules/infrastructure control | Standard business functions |
| Odoo.sh | Managed testing branches and upgrade workflow | Subscription and applicable licensing | Enterprise/customized deployments |
| Community on a VPS | Data/module/release control | Your team operates security, mail, backup and upgrades | Teams with Linux operations capacity |
Community does not grant Enterprise features or subscriptions. Third-party modules may have their own licenses. Inventory current modules, users, mail, local business requirements and downtime tolerance before comparing hosting prices.
| Workload | Starting resources | Qualification |
|---|---|---|
| Test or 1-3 users | 2 vCPU, 4 GB, 50 GB NVMe | Avoid important production data |
| Small team, 5-15 users | 4 vCPU, 8 GB, 100 GB NVMe | A few workers plus database/proxy |
| 20-50 users or heavy reports | 8 vCPU, 16 GB, 200 GB+ NVMe | Load-test and consider a separate database |
| Many attachments/product images | Suitable compute plus independent storage/backups | Include IOPS and restore time |
These are estimates. Prefer reliable storage and sustained CPU; measure your workload. Budget /var/lib/odoo, images, logs and temporary backups as well as PostgreSQL. More CPU alone does not repair high write latency.
- Ubuntu 24.04 VPS.
- Working domain such as
erp.example.com. - Supported Docker Engine/Compose v2.
- Public TCP 80/443 and restricted management SSH.
- Different strong database-owner/application passwords and an independent Odoo master password.
docker --version
docker compose version
free -h
df -h
sudo ss -lntup | grep -E ':(80|443|8069|8072|5432)\b' || true
Keep 8069, 8072 and 5432 off the public interface; users enter through Caddy HTTPS.
sudo mkdir -p /opt/odoo19/{config,addons,postgres-init,backups}
sudo chown -R "$USER":"$USER" /opt/odoo19
cd /opt/odoo19
umask 077
Create .env:
POSTGRES_DB=odoo
POSTGRES_USER=odoo_db_owner
POSTGRES_PASSWORD=替换为数据库所有者强密码
ODOO_DB_USER=odoo_app
ODOO_DB_PASSWORD=替换为不同的应用数据库强密码
Replace every example password value with a distinct random value. Hex secrets avoid shell/Compose ambiguity; the file is later sourced as Bash, so review it as executable configuration and protect it.
chmod 600 .env
The odoo_app application account is distinct from the database initializer and has neither superuser nor CREATEDB rights.
Create postgres-init/01-odoo-role.sh:
#!/bin/sh
set -eu
psql -v ON_ERROR_STOP=1 \
--username "$POSTGRES_USER" \
--dbname "$POSTGRES_DB" \
--set=odoo_password="$ODOO_DB_PASSWORD" <<'SQL'
CREATE ROLE odoo_app
LOGIN
PASSWORD :'odoo_password'
NOSUPERUSER
NOCREATEDB
NOCREATEROLE;
GRANT CONNECT ON DATABASE odoo TO odoo_app;
GRANT USAGE, CREATE ON SCHEMA public TO odoo_app;
SQL
chmod 700 postgres-init/01-odoo-role.sh
Init scripts run only on the first empty-cluster startup. Fix ownership before that startup: a deploy-owned mode-700 script cannot be executed by the container's PostgreSQL user. Inspect the selected image UID/GID, assign the init script to that user and make its directory traversable. Install required trusted extensions, such as unaccent and pg_trgm when needed, through an authorized database owner during initialization; the sample role only has CONNECT plus public-schema privileges. Test your actual modules' requirements without granting blanket superuser access.
Do not remove an existing production volume to rerun initialization.
Create config/odoo.conf:
[options]
admin_passwd = 替换为独立的Odoo主密码
db_host = db
db_port = 5432
db_name = odoo
dbfilter = ^odoo$
list_db = False
proxy_mode = True
workers = 3
max_cron_threads = 1
gevent_port = 8072
limit_time_cpu = 600
limit_time_real = 1200
limit_memory_soft = 1610612736
limit_memory_hard = 2147483648
addons_path = /usr/lib/python3/dist-packages/odoo/addons,/mnt/extra-addons
data_dir = /var/lib/odoo
admin_passwd is the database-management master password, separate from an administrator's login. list_db=False with fixed db_name and dbfilter narrows database selection. Enable proxy_mode=True only behind a trusted proxy.
Three workers is an estimate for 4 vCPU/8 GB. Their per-worker memory limits multiply, with cron/database/host overhead added; measure or reduce workers rather than treating that budget as guaranteed.
chmod 600 config/odoo.conf
mkdir -p addons
The official image runs as odoo. A deploy-owned mode-600 config is unreadable to it: assign the config to the actual image UID/GID with mode 600, and make the config/addons directories traversable and module files readable by that user. Keep secrets private. Record actual ownership rather than assuming a universal numeric UID.
Install third-party addons only after confirming Odoo 19 compatibility and dependencies in a test database; modules execute code inside the ERP server.
Create compose.yaml:
name: odoo19
services:
db:
image: postgres:16
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ODOO_DB_PASSWORD: ${ODOO_DB_PASSWORD}
volumes:
- postgres-data:/var/lib/postgresql/data
- ./postgres-init:/docker-entrypoint-initdb.d:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 10
networks:
- backend
odoo:
image: odoo:19.0-20260908
restart: unless-stopped
depends_on:
db:
condition: service_healthy
environment:
HOST: db
PORT: 5432
USER: ${ODOO_DB_USER}
PASSWORD: ${ODOO_DB_PASSWORD}
command: ["odoo", "-c", "/etc/odoo/odoo.conf"]
volumes:
- odoo-data:/var/lib/odoo
- ./config:/etc/odoo:ro
- ./addons:/mnt/extra-addons
expose:
- "8069"
- "8072"
networks:
- frontend
- backend
caddy:
image: caddy:2.10-alpine
restart: unless-stopped
depends_on:
- odoo
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy-data:/data
- caddy-config:/config
networks:
- frontend
networks:
frontend:
backend:
internal: true
volumes:
postgres-data:
odoo-data:
caddy-data:
caddy-config:
The original date-tag example is 19.0-20260908. On November 16, 2026, the official image list lists 19.0-20261112 for Odoo 19. Replace the original tag with that reviewed 19-series tag/digest before deployment, and select supported PostgreSQL 16 and Caddy patches. Do not use latest, which now follows Odoo 20. Pin actual image identities after testing.
PostgreSQL has no ports; Odoo is available only to its intended network peers and Caddy. Complete the ownership checks described above before initialization.
docker compose config > /tmp/odoo19-compose.resolved.yaml
grep -nE 'image:|POSTGRES_DB:|POSTGRES_USER:|HOST:|USER:' \
/tmp/odoo19-compose.resolved.yaml
The resolved file contains passwords. Keep its permissions private and remove the diagnostic copy when done; do not commit or share it.
Create Caddyfile with your hostname:
erp.example.com {
encode zstd gzip
@websocket path /websocket /websocket/*
reverse_proxy @websocket odoo:8072
reverse_proxy odoo:8069
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains"
X-Content-Type-Options "nosniff"
Referrer-Policy "strict-origin-when-cross-origin"
}
log {
output file /data/access.log {
roll_size 50MiB
roll_keep 5
}
}
}
Odoo's public deployment needs HTTPS and correct proxy mode. Realtime functions use /websocket/ on the gevent port; ordinary 8069 proxying alone is insufficient. Ensure DNS and public 80/443 work, preserve Caddy state, and apply HSTS/includeSubDomains only to HTTPS-capable hostnames.
Start the database:
docker compose pull
docker compose up -d db
docker compose ps
docker compose logs --tail=100 db
After health and logs confirm readiness, initialize before opening the public gateway:
docker compose run --rm odoo \
odoo -c /etc/odoo/odoo.conf \
-d odoo -i base --without-demo=all --stop-after-init
Set new administrator credentials immediately:
read -rsp "新的 Odoo 管理员密码: " ODOO_ADMIN_PASSWORD; echo
docker compose run --rm -T \
-e ODOO_ADMIN_PASSWORD="$ODOO_ADMIN_PASSWORD" \
odoo odoo shell -c /etc/odoo/odoo.conf -d odoo <<'PY'
import os
admin = env.ref('base.user_admin')
admin.write({
'login': '[email protected]',
'password': os.environ['ODOO_ADMIN_PASSWORD'],
})
env.cr.commit()
PY
unset ODOO_ADMIN_PASSWORD
Use a deliberate private [email protected] login; do not retain default credentials. Then:
docker compose up -d
docker compose ps
docker compose logs --tail=100 odoo caddy
Open https://erp.example.com, set company, local time zone and mail, and install only needed modules. Adding modules changes schema, jobs and resource demand.
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 443/udp
sudo ufw enable
sudo ufw status verbose
Ensure your active SSH port/source is permitted before enabling UFW. Docker publication also needs review; UFW alone does not establish the container boundary.
curl -I https://erp.example.com
curl -I https://erp.example.com/web/database/manager
Expect a successful page or legitimate login redirect, not exposed database creation/deletion/copying. Check list_db=False, db_name, dbfilter and the actual loaded configuration before inviting users. Restricted database selection is part of the boundary, not permission to share the master password.
Invitations, password resets, quotes and notifications need working mail. VPS egress 25 restrictions and direct-send IP reputation/PTR can complicate running your own server. A reputable SMTP provider on its supported 587/STARTTLS or 465/TLS route is often simpler.
Configure the outgoing mail server in Odoo's technical settings. Check actual inbox delivery, spam and bounces; a connection test alone is insufficient. Configure SPF/DKIM/DMARC for the real sender and provider.
Records live in PostgreSQL; attachments commonly live in /var/lib/odoo/filestore/. A database-only backup can leave broken attachments, while file-only copies lack their record relationships.
The conservative stopped-write sketch is:
cd /opt/odoo19
set -a
. ./.env
set +a
STAMP=$(date +%Y%m%d-%H%M%S)
BACKUP_DIR="$PWD/backups/$STAMP"
mkdir -p "$BACKUP_DIR"
docker compose stop odoo
docker compose exec -T db \
pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Fc \
> "$BACKUP_DIR/odoo.dump"
docker run --rm \
-v odoo19_odoo-data:/source:ro \
-v "$BACKUP_DIR":/backup \
alpine:3.22 \
tar -czf /backup/odoo-data.tar.gz -C /source .
tar -czf "$BACKUP_DIR/odoo-config.tar.gz" \
compose.yaml Caddyfile config addons postgres-init
sha256sum "$BACKUP_DIR"/* > "$BACKUP_DIR/SHA256SUMS"
docker compose start odoo
Before running it, enable strict error handling, use a unique backup directory and verify the actual volume name rather than assuming the fixed Compose prefix. Include the protected .env as well as config, custom addons/init scripts and gateway settings; the sketch's tar does not include .env. Check dump readability, archive contents and hashes before accepting the backup and restarting writes.
Keep independent offsite copies with retention. Encrypt .env and admin_passwd material; never publish the archives. See restore drills.
pg_restore --listmust read the dump successfully.- Database and filestore must share the same stopped-write window.
- Test login, files, images, mail templates and critical business modules in isolation.
- Restore the matching custom-module code.
- Measure recovery time against your RTO.
Rehearse at least quarterly, disabling actual email/payments/integrations in the test environment.
- Within 19.0, test supported bug/security updates against a restored copy.
- Moving from 18 to 19 needs database/module migration, not only an image-tag change.
docker compose pull odoo
docker compose up -d odoo
docker compose logs -f --tail=200 odoo
A pinned date tag/digest requires an explicit image update; pull alone does not select a newer date tag. Record the old image and full consistent backup first. Major upgrades need a tested migrated database, supported modules and a maintenance cutover. Avoid unattended major-image replacement.
- Host memory/swap, disk/inodes and latency.
- Database connections, slow queries, size and backup results.
- Odoo restarts, HTTP 5xx, latency and failed cron jobs.
- Certificate renewal and unusual proxy traffic.
- HTTPS/login response and real mail delivery.
For restarts, inspect docker compose ps and docker compose logs --tail=200 odoo db. Use disk troubleshooting without deleting durable Odoo volumes.
docker compose ps
docker compose logs --tail=200 db odoo
docker compose exec db pg_isready -U odoo_db_owner -d odoo
docker compose exec db psql -U odoo_db_owner -d odoo -c '\du'
Confirm the odoo_app role, real credentials, database readiness and internal DNS. Keep 5432 private; see PostgreSQL troubleshooting.
docker compose logs --tail=200 caddy odoo
docker compose exec caddy wget -S -O- http://odoo:8069/web/login
docker stats --no-stream
Distinguish application startup/migration, OOM and proxy reachability. Add RAM or reduce workers for OOM; repeated restarts are not a capacity fix. See proxy diagnosis.
Check consistent HTTPS, proxy_mode=True, server time, cookies and protocol forwarding at each trusted proxy.
Check /websocket routing to 8072 and logs:
docker compose exec caddy caddy validate --config /etc/caddy/Caddyfile
docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile
Restore pre-install database/filestore in a test environment and verify Odoo 19/Python/migration requirements. Deleting a module directory alone does not repair recorded installation state.
- Only planned SSH/80/443 are public; 5432/8069/8072 stay private.
- Application database role is non-superuser without CREATEDB.
list_db=False, fixeddb_nameanddbfilterare verified.- Default login password and
admin_passwdare independently replaced. - HTTPS, WebSockets, SMTP and resets pass real tests.
- Database, filestore, config and addons have consistent offsite backups.
- An isolated restore is documented.
- Tags/digests and migration-aware rollback are tested.
- Disk, 5xx, restarts and backup-failure alerts work.
docker compose up -d starts containers; reliable operation requires coordinated data, files, mail and upgrades. Recheck resources with actual workers and reports. If the team cannot sustain backups and incident handling, choose suitable managed Odoo support rather than budgeting only the VPS rental.