12 KiB
TrueNAS Nginx Proxy Manager App → Docker Migration
This guide covers migrating an Nginx Proxy Manager instance from a TrueNAS App (Kubernetes/k3s) to a Docker container.
Scripts
| Script | Purpose | Run On |
|---|---|---|
backup-nginx-proxy-manager-truenas.sh |
Backup NPM from TrueNAS App | TrueNAS host |
restore-nginx-proxy-manager-docker.sh |
Restore NPM to Docker | Docker host |
Prerequisites
On TrueNAS Host
- TrueNAS with Nginx Proxy Manager app installed
- SSH access to TrueNAS (or TrueNAS Shell)
k3s kubectlavailable (usually at/usr/local/bin/k3s kubectl)sqlite3(for SQLite) ormariadb-dump/mysqldump(for MariaDB) installed- Write access to backup destination dataset
On Docker Host
- Docker Engine installed
- Docker Compose (v2 plugin or standalone)
- Write access to Docker data directory
- Ports 80, 81, 443 available
Quick Start
1. Backup on TrueNAS
# SSH into TrueNAS
ssh root@truenas.local
# Copy the backup script to TrueNAS
scp backup-nginx-proxy-manager-truenas.sh root@truenas.local:/tmp/
# Run the backup script
APP_NAMESPACE=nginx-proxy-manager \
BACKUP_DEST=/mnt/tank/backups/npm \
/tmp/backup-nginx-proxy-manager-truenas.sh
Environment Variables for Backup:
| Variable | Default | Description |
|---|---|---|
APP_NAMESPACE |
nginx-proxy-manager |
Kubernetes namespace of NPM app |
BACKUP_DEST |
/mnt/tank/backups/npm |
Destination dataset path |
DB_TYPE |
sqlite |
Database type: sqlite or mariadb |
DB_HOST |
auto-detect | Database host (MariaDB only) |
DB_PORT |
auto-detect | Database port (3306 MariaDB) |
DB_NAME |
npm |
Database name |
DB_USER |
npm |
Database user |
DB_PASS |
auto-detect | Database password |
PVC_DATA |
auto-detect | Data PVC name (config, SQLite DB) |
PVC_LETS_ENCRYPT |
auto-detect | Let's Encrypt certificates PVC |
RETENTION_COUNT |
7 |
Number of backups to keep |
COMPRESSION_LEVEL |
6 |
gzip compression (1-9) |
2. Transfer Backup to Docker Host
# From your workstation, pull the backup from TrueNAS
scp root@truenas.local:/mnt/tank/backups/npm/npm_backup_*.tar.gz* .
# Copy to Docker host
scp npm_backup_*.tar.gz* user@docker-host:/opt/npm/
3. Restore on Docker Host
# SSH into Docker host
ssh user@docker-host
# Make scripts executable
chmod +x restore-nginx-proxy-manager-docker.sh
# Run restore (SQLite - default, no DB passwords needed)
./restore-nginx-proxy-manager-docker.sh /opt/npm/npm_backup_20240115_120000.tar.gz
# OR for MariaDB:
DB_TYPE=mariadb \
DB_ROOT_PASS=your_root_password \
DB_PASS=your_npm_password \
./restore-nginx-proxy-manager-docker.sh /opt/npm/npm_backup_20240115_120000.tar.gz
Environment Variables for Restore:
| Variable | Default | Description |
|---|---|---|
DOCKER_DIR |
/opt/npm |
Docker project directory |
COMPOSE_FILE |
docker-compose.yml |
Compose filename |
DB_CONTAINER |
npm-db |
Database container name (MariaDB only) |
NPM_CONTAINER |
nginx-proxy-manager |
NPM container name |
DB_TYPE |
sqlite |
Database type: sqlite or mariadb |
DB_ROOT_PASS |
required for MariaDB | Database root password |
DB_NAME |
npm |
Database name |
DB_USER |
npm |
Database user |
DB_PASS |
required for MariaDB | Database user password |
NPM_DATA_DIR |
${DOCKER_DIR}/npm-data |
Host data directory |
SKIP_DB |
false |
Skip database restore |
SKIP_FILES |
false |
Skip files restore |
FORCE |
false |
Skip confirmations |
4. Configure and Start NPM
cd /opt/npm
# Edit .env with your passwords (if using MariaDB)
nano .env
# Start containers
docker-compose up -d
# Check logs
docker-compose logs -f nginx-proxy-manager
5. Access Nginx Proxy Manager
Open your browser to http://<docker-host>:81
Default login (CHANGE IMMEDIATELY!):
- Email:
admin@example.com - Password:
changeme
Detailed Workflow
Backup Process (TrueNAS)
The backup script performs these steps:
- Detection: Finds Kubernetes namespace, database type, and PVCs
- Manifests: Exports all K8s resources
- Database:
- SQLite: Backed up as part of data PVC (file:
data/database.sqlite) - MariaDB: Dumps database with
mariadb-dump
- SQLite: Backed up as part of data PVC (file:
- Files: Creates temporary pods to copy data from PVCs:
data/→ NPM data directory (config, SSL certs, SQLite DB)letsencrypt/→ Let's Encrypt certificates (if separate PVC)
- Archive: Creates compressed
.tar.gzwith checksum - Cleanup: Removes old backups per retention policy
- Info: Generates
RESTORE_INFO_<timestamp>.txt
Restore Process (Docker)
The restore script performs these steps:
- Validation: Verifies backup archive integrity (checksum)
- Extraction: Unpacks backup to temporary directory
- Docker Compose: Generates
docker-compose.ymland.envtemplate - Database (MariaDB only): Recreates database and restores from SQL dump
- Files: Syncs data and letsencrypt directories to host
- Guidance: Shows next steps including default login credentials
Docker Compose Structure
The generated docker-compose.yml creates:
SQLite (Default)
npm/
├── docker-compose.yml
├── .env # Your config
├── npm-backup_*.tar.gz # Backup archive
├── npm-backup_*.sha256 # Checksum
├── RESTORE_INFO_*.txt # Restore documentation
└── npm-data/
├── data/ # NPM config, database.sqlite, custom SSL
│ ├── database.sqlite
│ ├── config/
│ └── custom_ssl/
└── letsencrypt/ # Let's Encrypt certificates
├── live/
└── archive/
MariaDB
npm/
├── docker-compose.yml
├── .env # Your passwords (EDIT THIS!)
├── npm-backup_*.tar.gz
├── npm-backup_*.sha256
├── RESTORE_INFO_*.txt
└── npm-data/
├── data/ # NPM config, custom SSL
└── letsencrypt/ # Let's Encrypt certificates
(Database stored in Docker volume db-data)
Database Options
SQLite (Default, Simpler)
- Pros: No separate database container, simpler setup, portable
- Cons: Less performant for high-traffic setups
- Backup: Single file
data/database.sqlitein data PVC - Restore: Automatic with file restore
MariaDB (Production Recommended)
- Pros: Better performance, concurrent access, standard SQL
- Cons: Extra container, more complex
- Backup: SQL dump via
mariadb-dump - Restore: Requires
DB_ROOT_PASSandDB_PASS
To use MariaDB:
# Backup (TrueNAS) - auto-detects if MariaDB secret exists
DB_TYPE=mariadb ./backup-nginx-proxy-manager-truenas.sh
# Restore (Docker)
DB_TYPE=mariadb \
DB_ROOT_PASS=strong_root_pass \
DB_PASS=strong_user_pass \
./restore-nginx-proxy-manager-docker.sh backup.tar.gz
Common Scenarios
Migration with SQLite (Default)
# TrueNAS backup (auto-detects SQLite)
./backup-nginx-proxy-manager-truenas.sh
# Docker restore (no DB passwords needed)
./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz
Migration with MariaDB
# TrueNAS backup
DB_TYPE=mariadb ./backup-nginx-proxy-manager-truenas.sh
# Docker restore
DB_TYPE=mariadb \
DB_ROOT_PASS=xxx DB_PASS=yyy \
./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz
Only Restore Certificates (Let's Encrypt)
SKIP_DB=true \
./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz
Custom Data Directory
NPM_DATA_DIR=/data/npm \
./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz
Nginx Proxy Manager Specific Notes
Default Login Credentials
After first startup, immediately change the default admin:
- Email:
admin@example.com - Password:
changeme
Proxy Host Configuration
After restore, verify all proxy hosts:
- Check Hosts → Proxy Hosts - all entries should appear
- Verify Forward Hostname/IP - may need updates if Docker network changed
- Test each proxy host works
SSL Certificates
Let's Encrypt certificates in letsencrypt/ restore automatically:
live/- Active certificatesarchive/- Certificate historyrenewal/- Renewal configs
Certificates should work immediately if domain names unchanged.
Custom SSL Certificates
Custom SSL certs stored in data/custom_ssl/ restore automatically.
Access Lists & Audit Logs
- Access lists: Restored from database
- Audit logs: Restored from database (SQLite or MariaDB)
Network Considerations
Important: If your Docker host IP changed, update proxy host forward IPs:
- Old:
192.168.1.100:8080(TrueNAS app IP) - New:
172.17.0.5:8080(Docker container IP) or service name
Use Docker service names when possible:
# Instead of IP, use service name
Forward Hostname: nextcloud
Port: 80
Troubleshooting
Backup Fails: "Database dump failed" (MariaDB)
- Check database credentials
- Ensure
mariadb-dumpinstalled on TrueNAS - Verify database accessible:
mariadb -h <DB_HOST> -u <DB_USER> -p<DB_PASS> <DB_NAME> -e "SELECT 1"
Backup Fails: "PVC not found"
- Check PVC names:
k3s kubectl get pvc -n nginx-proxy-manager - Set
PVC_DATA,PVC_LETS_ENCRYPTexplicitly
Restore Fails: "Database not ready" (MariaDB)
- Check database logs:
docker-compose logs db - Ensure
DB_ROOT_PASSin.envmatches restore script - Check MariaDB healthcheck passes
NPM Web UI Not Accessible
- Check container running:
docker-compose ps - Check logs:
docker-compose logs nginx-proxy-manager - Verify ports 80, 81, 443 not used by host
- Check firewall allows ports
Proxy Hosts Show 502 Bad Gateway
- Verify upstream service is running
- Check forward hostname/IP in proxy host config
- Use Docker service names instead of IPs
- Check Docker network connectivity:
docker exec nginx-proxy-manager ping nextcloud
SSL Certificate Errors
- Check certificates exist in
npm-data/letsencrypt/live/ - Verify certificate matches domain
- Force renewal in NPM UI: SSL Certificates → Force Renewal
Permission Issues
NPM runs as root (UID 0) in container, so permissions are usually fine. If issues:
docker run --rm -v /opt/npm/npm-data:/data alpine:latest \
sh -c "chown -R 0:0 /data && chmod -R 755 /data"
Security Notes
- Change default admin password immediately!
- Never commit
.envto version control - contains passwords (MariaDB) - Use strong passwords for
DB_ROOT_PASSandDB_PASS(MariaDB) - Restrict backup access - archives contain SSL private keys!
- Use HTTPS for admin UI - put NPM behind itself or another proxy
- Regular backups - Set up automated backups for Docker deployment
- Update NPM regularly -
docker-compose pull && docker-compose up -d
File Structure After Restore
/opt/npm/
├── docker-compose.yml
├── .env # ← EDIT THIS (MariaDB passwords)
├── npm_backup_*.tar.gz # Backup archive
├── npm_backup_*.sha256 # Checksum
├── RESTORE_INFO_*.txt # Restore documentation
└── npm-data/
├── data/
│ ├── database.sqlite # SQLite DB (if used)
│ ├── config/
│ │ └── production.json # NPM config
│ └── custom_ssl/ # Custom SSL certificates
└── letsencrypt/
├── live/ # Active certs
├── archive/ # Cert history
└── renewal/ # Renewal configs
Support
If you encounter issues:
- Check log output from both scripts
- Verify all prerequisites met
- Check TrueNAS app logs:
k3s kubectl logs -n nginx-proxy-manager -l app=nginx-proxy-manager - Check Docker logs:
docker-compose logs nginx-proxy-manager - Verify network connectivity:
docker exec nginx-proxy-manager ping <upstream-service>
License
MIT License - Feel free to use and modify for your needs.