Add docker examples for restore services up

This commit is contained in:
2026-10-24 13:13:14 +03:00
parent 8b6b9e6093
commit 31aa977b3b
18 changed files with 926 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
# Nginx Proxy Manager Docker Environment
# Copy to .env and fill in your values
# Database type: sqlite or mariadb
# Use 'docker-compose --profile sqlite up -d' for SQLite
# Use 'docker-compose --profile mariadb up -d' for MariaDB
DB_TYPE=sqlite
# MariaDB settings (only used if DB_TYPE=mariadb)
DB_ROOT_PASS=changeme_strong_root_password
DB_NAME=npm
DB_USER=npm
DB_PASS=changeme_strong_user_password
# NPM
NPM_DATA_DIR=./npm-data
HTTP_PORT=80
ADMIN_PORT=81
HTTPS_PORT=443
+19
View File
@@ -0,0 +1,19 @@
# Nginx Proxy Manager Docker Image
# Based on official jc21/nginx-proxy-manager image
FROM jc21/nginx-proxy-manager:latest
# Install additional tools for maintenance
RUN apk add --no-cache \
mariadb-client \
postgresql-client \
sqlite \
openssl \
curl
# Copy custom entrypoint
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["/init"]
+171
View File
@@ -0,0 +1,171 @@
# Nginx Proxy Manager Docker Setup
Docker environment for running Nginx Proxy Manager restored from TrueNAS backup.
## Quick Start
### SQLite (Default - Simpler)
```bash
# 1. Copy environment template
cp .env.example .env
# 2. Start with SQLite profile
docker-compose --profile sqlite up -d
# 3. Access admin UI at http://localhost:81
# Default login: admin@example.com / changeme (CHANGE IMMEDIATELY!)
```
### MariaDB (Production)
```bash
# 1. Copy and edit environment
cp .env.example .env
nano .env
# Set: DB_TYPE=mariadb, DB_ROOT_PASS=xxx, DB_PASS=yyy
# 2. Start with MariaDB profile
docker-compose --profile mariadb up -d
# 3. Access admin UI at http://localhost:81
```
## Directory Structure
```
ep-npm-docker/
├── Dockerfile # Based on jc21/nginx-proxy-manager:latest
├── docker-entrypoint.sh # Handles permissions, DB wait
├── docker-compose.yml # SQLite OR MariaDB profiles
├── .env.example # Environment template
└── npm-data/ # Your data (create this)
├── data/ # Config, SSL certs, SQLite DB
└── letsencrypt/ # Let's Encrypt certificates
```
## Restore from Backup
After running the restore script on the Docker host:
```bash
# Symlink or copy to ./npm-data
ln -s ../npm-data ./npm-data
# OR
cp -r ../npm-data/* ./npm-data/
# Start appropriate profile
docker-compose --profile sqlite up -d
# OR
docker-compose --profile mariadb up -d
```
## Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| `DB_TYPE` | Database type: `sqlite` or `mariadb` | `sqlite` |
| `DB_ROOT_PASS` | MariaDB root password | required for MariaDB |
| `DB_NAME` | Database name | `npm` |
| `DB_USER` | Database user | `npm` |
| `DB_PASS` | Database user password | required for MariaDB |
| `NPM_DATA_DIR` | Host data directory | `./npm-data` |
| `HTTP_PORT` | HTTP port | `80` |
| `ADMIN_PORT` | Admin UI port | `81` |
| `HTTPS_PORT` | HTTPS port | `443` |
## Profiles
- **sqlite** (default): No separate DB container, uses SQLite file in `data/database.sqlite`
- **mariadb**: Uses MariaDB 10.11 container, better for high-traffic setups
```bash
# SQLite
docker-compose --profile sqlite up -d
# MariaDB
docker-compose --profile mariadb up -d
```
## Default Login
After first startup:
- **Email:** `admin@example.com`
- **Password:** `changeme`
**CHANGE IMMEDIATELY!** Go to Settings → Users → Edit admin user.
## Post-Restore Steps
1. **Verify Proxy Hosts** - Check Hosts → Proxy Hosts
2. **Update Forward IPs** - If Docker network changed, update forward hostnames/IPs
3. **Test SSL Certificates** - Check SSL Certificates tab, force renewal if needed
4. **Verify Access Lists** - Check Access Lists tab
## Custom Entrypoint Features
The custom `docker-entrypoint.sh`:
- Fixes permissions on data/ and letsencrypt/ directories
- Waits for MariaDB if using MariaDB profile
## Ports
| Port | Purpose |
|------|---------|
| 80 | HTTP traffic |
| 81 | Admin Web UI |
| 443 | HTTPS traffic |
## Logs
```bash
# View NPM logs
docker-compose logs -f npm
# View DB logs (MariaDB only)
docker-compose logs -f db
```
## Backup (Docker-side)
```bash
# SQLite - backup database file
cp npm-data/data/database.sqlite backup_db_$(date +%Y%m%d).sqlite
# MariaDB
docker-compose exec db mariadb-dump -u root -p"$DB_ROOT_PASS" npm > backup_$(date +%Y%m%d).sql
# Files (both)
tar -czf npm_files_$(date +%Y%m%d).tar.gz npm-data/
```
## Stopping
```bash
docker-compose --profile sqlite down
# OR
docker-compose --profile mariadb down
```
## Security Notes
1. **Change default admin password immediately!**
2. **Use strong passwords** in `.env` for MariaDB
3. **Restrict admin UI access** - put behind VPN or allowlist IPs
4. **Use HTTPS** - NPM manages Let's Encrypt certs automatically
5. **Regular backups** - Both database and letsencrypt certificates
## Troubleshooting
### 502 Bad Gateway
- Check upstream service is running
- Use Docker service names instead of IPs (e.g., `nextcloud` instead of `172.17.0.x`)
- Verify proxy host configuration
### SSL Certificate Errors
- Check certificates exist in `npm-data/letsencrypt/live/`
- Force renewal in NPM UI: SSL Certificates → Force Renewal
- Check Let's Encrypt rate limits
### Admin UI Not Accessible
- Check container running: `docker-compose ps`
- Check logs: `docker-compose logs npm`
- Verify port 81 not blocked by firewall
+73
View File
@@ -0,0 +1,73 @@
version: '3.8'
services:
# SQLite version (default - no separate DB container needed)
npm:
image: jc21/nginx-proxy-manager:latest
container_name: ep-npm
restart: unless-stopped
ports:
- "${HTTP_PORT:-80}:80"
- "${ADMIN_PORT:-81}:81"
- "${HTTPS_PORT:-443}:443"
volumes:
- ${NPM_DATA_DIR:-./npm-data}/data:/data
- ${NPM_DATA_DIR:-./npm-data}/letsencrypt:/etc/letsencrypt
networks:
- npm-net
profiles:
- sqlite
# MariaDB version
npm-mariadb:
build: .
container_name: ep-npm
restart: unless-stopped
depends_on:
db:
condition: service_healthy
ports:
- "${HTTP_PORT:-80}:80"
- "${ADMIN_PORT:-81}:81"
- "${HTTPS_PORT:-443}:443"
environment:
DB_MYSQL_HOST: db
DB_MYSQL_PORT: 3306
DB_MYSQL_DATABASE: ${DB_NAME:-npm}
DB_MYSQL_USER: ${DB_USER:-npm}
DB_MYSQL_PASSWORD: ${DB_PASS}
volumes:
- ${NPM_DATA_DIR:-./npm-data}/data:/data
- ${NPM_DATA_DIR:-./npm-data}/letsencrypt:/etc/letsencrypt
networks:
- npm-net
profiles:
- mariadb
db:
image: mariadb:10.11
container_name: ep-npm-db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS}
MYSQL_DATABASE: ${DB_NAME:-npm}
MYSQL_USER: ${DB_USER:-npm}
MYSQL_PASSWORD: ${DB_PASS}
volumes:
- db-data:/var/lib/mysql
networks:
- npm-net
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
profiles:
- mariadb
volumes:
db-data:
networks:
npm-net:
driver: bridge
+32
View File
@@ -0,0 +1,32 @@
#!/bin/bash
# Custom entrypoint for Nginx Proxy Manager Docker container
# Handles restore initialization and permission fixes
set -e
# Fix permissions on mounted volumes
if [ -d "/data" ]; then
chown -R root:root /data 2>/dev/null || true
chmod -R 755 /data 2>/dev/null || true
fi
if [ -d "/etc/letsencrypt" ]; then
chown -R root:root /etc/letsencrypt 2>/dev/null || true
chmod -R 755 /etc/letsencrypt 2>/dev/null || true
fi
# If database is MariaDB, wait for it
if [ -n "${DB_MYSQL_HOST}" ] && [ "${DB_MYSQL_HOST}" != "sqlite" ]; then
echo "Waiting for MariaDB database..."
for i in {1..30}; do
if mariadb -h "${DB_MYSQL_HOST}" -P "${DB_MYSQL_PORT:-3306}" -u "${DB_MYSQL_USER}" -p"${DB_MYSQL_PASSWORD}" -e "SELECT 1" "${DB_MYSQL_DATABASE}" >/dev/null 2>&1; then
echo "MariaDB connection successful"
break
fi
echo "Waiting for MariaDB... ($i/30)"
sleep 2
done
fi
# Execute original entrypoint
exec /usr/local/bin/docker-entrypoint.sh "$@"