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
+149
View File
@@ -0,0 +1,149 @@
# Nextcloud Docker Setup
Docker environment for running Nextcloud restored from TrueNAS backup.
## Quick Start
```bash
# 1. Copy environment template
cp .env.example .env
# 2. Edit .env with your database passwords and trusted domains
nano .env
# IMPORTANT: Set NEXTCLOUD_TRUSTED_DOMAINS=your-domain.com,localhost,192.168.x.x
# 3. Place your backup data in ./nextcloud-data/
# Structure should be:
# nextcloud-data/
# ├── data/ # From backup data/
# ├── config/ # From backup config/ (contains config.php)
# └── custom_apps/ # From backup apps/ (if any)
# 4. Start containers
docker-compose up -d
# 5. Access Nextcloud at http://localhost:8080
```
## Directory Structure
```
ep-nextcloud-docker/
├── Dockerfile # Custom image with postgres/mariadb clients, optimized PHP
├── docker-entrypoint.sh # Handles permissions, DB wait, post-restore steps
├── docker-compose.yml # PostgreSQL + Redis + Nextcloud services
├── .env.example # Environment template
└── nextcloud-data/ # Your data (create this)
├── data/
├── config/
└── custom_apps/
```
## Restore from Backup
After running the restore script on the Docker host:
```bash
# Symlink or copy to ./nextcloud-data
ln -s ../nextcloud-data ./nextcloud-data
# OR
cp -r ../nextcloud-data/* ./nextcloud-data/
docker-compose up -d
```
The custom entrypoint will automatically:
1. Fix permissions on data/, config/, custom_apps/
2. Wait for database (PostgreSQL or MariaDB)
3. Disable maintenance mode
4. Run `occ upgrade`
5. Run `occ db:add-missing-indices`
6. Run `occ db:add-missing-primary-keys`
7. Run `occ db:convert-filecache-bigint`
## Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| `DB_ROOT_PASS` | PostgreSQL root password | **required** |
| `DB_NAME` | Database name | `nextcloud` |
| `DB_USER` | Database user | `nextcloud` |
| `DB_PASS` | Database user password | **required** |
| `NEXTCLOUD_DATA_DIR` | Host data directory | `./nextcloud-data` |
| `NEXTCLOUD_PORT` | Host port for web UI | `8080` |
| `NEXTCLOUD_TRUSTED_DOMAINS` | **Required** - comma-separated domains | `localhost` |
| `NEXTCLOUD_ADMIN_USER` | Admin user (fresh install only) | - |
| `NEXTCLOUD_ADMIN_PASSWORD` | Admin password (fresh install only) | - |
**Critical:** Set `NEXTCLOUD_TRUSTED_DOMAINS` before starting:
```bash
NEXTCLOUD_TRUSTED_DOMAINS=localhost,nextcloud.example.com,192.168.1.100
```
## Database
Uses **PostgreSQL 16** (recommended for Nextcloud). Data persisted in Docker volume `db-data`.
## Redis
Includes Redis 7 for memory caching. Configured automatically via environment variables.
## Health Checks
All services have health checks:
- PostgreSQL: `pg_isready`
- Redis: `redis-cli ping`
- Nextcloud: Depends on healthy DB + Redis
## Logs
```bash
# View Nextcloud logs
docker-compose logs -f nextcloud
# View DB logs
docker-compose logs -f db
# View Redis logs
docker-compose logs -f redis
```
## Useful Commands
```bash
# Run occ commands
docker-compose exec nextcloud php occ status
docker-compose exec nextcloud php occ maintenance:mode --off
docker-compose exec nextcloud php occ upgrade
docker-compose exec nextcloud php occ db:add-missing-indices
# Check config
docker-compose exec nextcloud cat /var/www/html/config/config.php
# Backup database
docker-compose exec db pg_dump -U nextcloud nextcloud > backup_$(date +%Y%m%d).sql
# Backup files
tar -czf nextcloud_files_$(date +%Y%m%d).tar.gz nextcloud-data/
```
## Cron Jobs (Recommended)
Add to host crontab for background jobs:
```bash
*/5 * * * * docker exec -u www-data ep-nextcloud php -f /var/www/html/cron.php
```
## Stopping
```bash
docker-compose down
```
## Switching to MariaDB
If you prefer MariaDB over PostgreSQL, modify `docker-compose.yml`:
- Change `db` service to `mariadb:10.11`
- Update environment variables to `MYSQL_*`
- Update Nextcloud environment to `MYSQL_*`
- Update healthcheck to `mysqladmin ping`