# 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 kubectl` available (usually at `/usr/local/bin/k3s kubectl`) - `sqlite3` (for SQLite) or `mariadb-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 ```bash # 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 ```bash # 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 ```bash # 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 ```bash 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://:81` **Default login (CHANGE IMMEDIATELY!):** - Email: `admin@example.com` - Password: `changeme` --- ## Detailed Workflow ### Backup Process (TrueNAS) The backup script performs these steps: 1. **Detection**: Finds Kubernetes namespace, database type, and PVCs 2. **Manifests**: Exports all K8s resources 3. **Database**: - SQLite: Backed up as part of data PVC (file: `data/database.sqlite`) - MariaDB: Dumps database with `mariadb-dump` 4. **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) 5. **Archive**: Creates compressed `.tar.gz` with checksum 6. **Cleanup**: Removes old backups per retention policy 7. **Info**: Generates `RESTORE_INFO_.txt` ### Restore Process (Docker) The restore script performs these steps: 1. **Validation**: Verifies backup archive integrity (checksum) 2. **Extraction**: Unpacks backup to temporary directory 3. **Docker Compose**: Generates `docker-compose.yml` and `.env` template 4. **Database** (MariaDB only): Recreates database and restores from SQL dump 5. **Files**: Syncs data and letsencrypt directories to host 6. **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.sqlite` in 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_PASS` and `DB_PASS` **To use MariaDB:** ```bash # 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) ```bash # 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 ```bash # 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) ```bash SKIP_DB=true \ ./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz ``` ### Custom Data Directory ```bash 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: 1. Check **Hosts → Proxy Hosts** - all entries should appear 2. Verify **Forward Hostname/IP** - may need updates if Docker network changed 3. Test each proxy host works ### SSL Certificates Let's Encrypt certificates in `letsencrypt/` restore automatically: - `live/` - Active certificates - `archive/` - Certificate history - `renewal/` - 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) 1. Check database credentials 2. Ensure `mariadb-dump` installed on TrueNAS 3. Verify database accessible: ```bash mariadb -h -u -p -e "SELECT 1" ``` ### Backup Fails: "PVC not found" 1. Check PVC names: `k3s kubectl get pvc -n nginx-proxy-manager` 2. Set `PVC_DATA`, `PVC_LETS_ENCRYPT` explicitly ### Restore Fails: "Database not ready" (MariaDB) 1. Check database logs: `docker-compose logs db` 2. Ensure `DB_ROOT_PASS` in `.env` matches restore script 3. Check MariaDB healthcheck passes ### NPM Web UI Not Accessible 1. Check container running: `docker-compose ps` 2. Check logs: `docker-compose logs nginx-proxy-manager` 3. Verify ports 80, 81, 443 not used by host 4. Check firewall allows ports ### Proxy Hosts Show 502 Bad Gateway 1. Verify upstream service is running 2. Check forward hostname/IP in proxy host config 3. Use Docker service names instead of IPs 4. Check Docker network connectivity: ```bash docker exec nginx-proxy-manager ping nextcloud ``` ### SSL Certificate Errors 1. Check certificates exist in `npm-data/letsencrypt/live/` 2. Verify certificate matches domain 3. 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: ```bash docker run --rm -v /opt/npm/npm-data:/data alpine:latest \ sh -c "chown -R 0:0 /data && chmod -R 755 /data" ``` --- ## Security Notes 1. **Change default admin password immediately!** 2. **Never commit `.env` to version control** - contains passwords (MariaDB) 3. **Use strong passwords** for `DB_ROOT_PASS` and `DB_PASS` (MariaDB) 4. **Restrict backup access** - archives contain SSL private keys! 5. **Use HTTPS for admin UI** - put NPM behind itself or another proxy 6. **Regular backups** - Set up automated backups for Docker deployment 7. **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: 1. Check log output from both scripts 2. Verify all prerequisites met 3. Check TrueNAS app logs: `k3s kubectl logs -n nginx-proxy-manager -l app=nginx-proxy-manager` 4. Check Docker logs: `docker-compose logs nginx-proxy-manager` 5. Verify network connectivity: `docker exec nginx-proxy-manager ping ` --- ## License MIT License - Feel free to use and modify for your needs.