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
+4
View File
@@ -61,6 +61,10 @@ BACKUP_DIR="${BACKUP_DEST}/nextcloud_backup_${TIMESTAMP}"
mkdir -p "${BACKUP_DIR}"
LOG_FILE="${BACKUP_DIR}/backup.log"
# Debug: show config values
echo "DEBUG: BACKUP_DEST='${BACKUP_DEST}'" >&2
echo "DEBUG: BACKUP_DIR='${BACKUP_DIR}'" >&2
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
+4
View File
@@ -56,6 +56,10 @@ BACKUP_DIR="${BACKUP_DEST}/npm_backup_${TIMESTAMP}"
mkdir -p "${BACKUP_DIR}"
LOG_FILE="${BACKUP_DIR}/backup.log"
# Debug: show config values
echo "DEBUG: BACKUP_DEST='${BACKUP_DEST}'" >&2
echo "DEBUG: BACKUP_DIR='${BACKUP_DIR}'" >&2
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
+4
View File
@@ -69,6 +69,10 @@ BACKUP_DIR="${BACKUP_DEST}/piwigo_backup_${TIMESTAMP}"
mkdir -p "${BACKUP_DIR}"
LOG_FILE="${BACKUP_DIR}/backup.log"
# Debug: show config values
echo "DEBUG: BACKUP_DEST='${BACKUP_DEST}'" >&2
echo "DEBUG: BACKUP_DIR='${BACKUP_DIR}'" >&2
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
+20
View File
@@ -0,0 +1,20 @@
# Nextcloud Docker Environment
# Copy to .env and fill in your values
# Database (PostgreSQL)
DB_ROOT_PASS=changeme_strong_root_password
DB_NAME=nextcloud
DB_USER=nextcloud
DB_PASS=changeme_strong_user_password
# Nextcloud
NEXTCLOUD_DATA_DIR=./nextcloud-data
NEXTCLOUD_PORT=8080
# Trusted domains (comma-separated, no spaces)
# Example: NEXTCLOUD_TRUSTED_DOMAINS=localhost,nextcloud.example.com,192.168.1.100
NEXTCLOUD_TRUSTED_DOMAINS=localhost
# Optional: Admin user for fresh install (ignored if restoring from backup)
# NEXTCLOUD_ADMIN_USER=admin
# NEXTCLOUD_ADMIN_PASSWORD=changeme_admin_password
+35
View File
@@ -0,0 +1,35 @@
# Nextcloud Docker Image
# Based on official Nextcloud image with optimizations for restore
FROM nextcloud:latest
# Install additional tools
RUN apt-get update && apt-get install -y \
postgresql-client \
mariadb-client \
rsync \
smbclient \
libmagickcore-6.q16-6-extra \
&& rm -rf /var/lib/apt/lists/*
# Set recommended PHP settings
RUN { \
echo 'memory_limit = 1G'; \
echo 'max_execution_time = 3600'; \
echo 'upload_max_filesize = 20G'; \
echo 'post_max_size = 20G'; \
echo 'max_file_uploads = 200'; \
echo 'opcache.enable = 1'; \
echo 'opcache.interned_strings_buffer = 8'; \
echo 'opcache.max_accelerated_files = 10000'; \
echo 'opcache.memory_consumption = 128'; \
echo 'opcache.save_comments = 1'; \
echo 'opcache.revalidate_freq = 1'; \
} > /usr/local/etc/php/conf.d/nextcloud-custom.ini
# Copy custom entrypoint
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]
+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`
+69
View File
@@ -0,0 +1,69 @@
version: '3.8'
services:
db:
image: postgres:16
container_name: ep-nextcloud-db
restart: unless-stopped
environment:
POSTGRES_PASSWORD: ${DB_ROOT_PASS}
POSTGRES_DB: ${DB_NAME:-nextcloud}
POSTGRES_USER: ${DB_USER:-nextcloud}
volumes:
- db-data:/var/lib/postgresql/data
networks:
- nextcloud-net
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-nextcloud} -d ${DB_NAME:-nextcloud}"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
container_name: ep-nextcloud-redis
restart: unless-stopped
networks:
- nextcloud-net
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
nextcloud:
build: .
container_name: ep-nextcloud
restart: unless-stopped
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
environment:
POSTGRES_HOST: db
POSTGRES_DB: ${DB_NAME:-nextcloud}
POSTGRES_USER: ${DB_USER:-nextcloud}
POSTGRES_PASSWORD: ${DB_PASS}
REDIS_HOST: redis
REDIS_HOST_PORT: 6379
NEXTCLOUD_TRUSTED_DOMAINS: ${NEXTCLOUD_TRUSTED_DOMAINS:-localhost}
NEXTCLOUD_ADMIN_USER: ${NEXTCLOUD_ADMIN_USER:-}
NEXTCLOUD_ADMIN_PASSWORD: ${NEXTCLOUD_ADMIN_PASSWORD:-}
PHP_MEMORY_LIMIT: 1G
PHP_MAX_EXECUTION_TIME: 3600
PHP_UPLOAD_MAX_FILESIZE: 20G
PHP_POST_MAX_SIZE: 20G
volumes:
- ${NEXTCLOUD_DATA_DIR:-./nextcloud-data}:/var/www/html
ports:
- "${NEXTCLOUD_PORT:-8080}:80"
networks:
- nextcloud-net
volumes:
db-data:
networks:
nextcloud-net:
driver: bridge
+76
View File
@@ -0,0 +1,76 @@
#!/bin/bash
# Custom entrypoint for Nextcloud Docker container
# Handles restore initialization, permission fixes, and maintenance mode
set -e
# Fix permissions on mounted volumes
if [ -d "/var/www/html/data" ]; then
chown -R www-data:www-data /var/www/html/data 2>/dev/null || true
find /var/www/html/data -type d -exec chmod 750 {} \; 2>/dev/null || true
find /var/www/html/data -type f -exec chmod 640 {} \; 2>/dev/null || true
fi
if [ -d "/var/www/html/config" ]; then
chown -R www-data:www-data /var/www/html/config 2>/dev/null || true
find /var/www/html/config -type f -exec chmod 640 {} \; 2>/dev/null || true
fi
if [ -d "/var/www/html/custom_apps" ]; then
chown -R www-data:www-data /var/www/html/custom_apps 2>/dev/null || true
find /var/www/html/custom_apps -type d -exec chmod 750 {} \; 2>/dev/null || true
find /var/www/html/custom_apps -type f -exec chmod 640 {} \; 2>/dev/null || true
fi
# If config exists, wait for database and run post-restore steps
if [ -f "/var/www/html/config/config.php" ]; then
echo "Config found, checking database connection..."
# Extract DB config
if grep -q "'dbtype' => 'pgsql'" /var/www/html/config/config.php; then
DB_TYPE="pgsql"
DB_HOST=$(grep -oP "'dbhost'\s*=>\s*'\K[^']+" /var/www/html/config/config.php 2>/dev/null || echo "db")
DB_PORT=$(grep -oP "'dbport'\s*=>\s*\K[0-9]+" /var/www/html/config/config.php 2>/dev/null || echo "5432")
else
DB_TYPE="mysql"
DB_HOST=$(grep -oP "'dbhost'\s*=>\s*'\K[^']+" /var/www/html/config/config.php 2>/dev/null || echo "db")
DB_PORT=$(grep -oP "'dbport'\s*=>\s*\K[0-9]+" /var/www/html/config/config.php 2>/dev/null || echo "3306")
fi
DB_USER=$(grep -oP "'dbuser'\s*=>\s*'\K[^']+" /var/www/html/config/config.php 2>/dev/null || echo "nextcloud")
DB_PASS=$(grep -oP "'dbpassword'\s*=>\s*'\K[^']+" /var/www/html/config/config.php 2>/dev/null || echo "")
DB_NAME=$(grep -oP "'dbname'\s*=>\s*'\K[^']+" /var/www/html/config/config.php 2>/dev/null || echo "nextcloud")
# Wait for database
for i in {1..60}; do
if [ "$DB_TYPE" = "pgsql" ]; then
if PGPASSWORD="$DB_PASS" pg_isready -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" >/dev/null 2>&1; then
echo "PostgreSQL connection successful"
break
fi
else
if mariadb -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" -p"$DB_PASS" -e "SELECT 1" "$DB_NAME" >/dev/null 2>&1; then
echo "MariaDB/MySQL connection successful"
break
fi
fi
echo "Waiting for database... ($i/60)"
sleep 2
done
# Disable maintenance mode if enabled
echo "Disabling maintenance mode..."
sudo -u www-data php /var/www/html/occ maintenance:mode --off 2>/dev/null || true
# Run upgrade if needed
echo "Running Nextcloud upgrade..."
sudo -u www-data php /var/www/html/occ upgrade 2>/dev/null || true
# Fix database
echo "Fixing database schema..."
sudo -u www-data php /var/www/html/occ db:add-missing-indices 2>/dev/null || true
sudo -u www-data php /var/www/html/occ db:add-missing-primary-keys 2>/dev/null || true
sudo -u www-data php /var/www/html/occ db:convert-filecache-bigint --no-interaction 2>/dev/null || true
fi
# Execute original entrypoint
exec /usr/local/bin/docker-entrypoint.sh "$@"
+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 "$@"
+12
View File
@@ -0,0 +1,12 @@
# Piwigo Docker Environment
# Copy to .env and fill in your values
# Database
DB_ROOT_PASS=changeme_strong_root_password
DB_NAME=piwigo
DB_USER=piwigo
DB_PASS=changeme_strong_user_password
# Piwigo
PIWIGO_DATA_DIR=./piwigo-data
PIWIGO_PORT=8080
+30
View File
@@ -0,0 +1,30 @@
# Piwigo Docker Image
# Based on official Piwigo image with optimizations for restore
FROM piwigo:latest
# Install additional tools for maintenance
RUN apt-get update && apt-get install -y \
mariadb-client \
rsync \
&& rm -rf /var/lib/apt/lists/*
# Set recommended PHP settings
RUN { \
echo 'memory_limit = 512M'; \
echo 'max_execution_time = 300'; \
echo 'upload_max_filesize = 100M'; \
echo 'post_max_size = 100M'; \
echo 'max_file_uploads = 50'; \
} > /usr/local/etc/php/conf.d/piwigo-custom.ini
# Create directory structure
RUN mkdir -p /var/www/html/upload /var/www/html/local/config /var/www/html/galleries \
&& chown -R www-data:www-data /var/www/html
# Copy custom entrypoint for restore support
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]
+110
View File
@@ -0,0 +1,110 @@
# Piwigo Docker Setup
Docker environment for running Piwigo restored from TrueNAS backup.
## Quick Start
```bash
# 1. Copy environment template
cp .env.example .env
# 2. Edit .env with your database passwords
nano .env
# 3. Place your backup data in ./piwigo-data/
# Structure should be:
# piwigo-data/
# ├── upload/ # From backup uploads/
# ├── local/config/ # From backup config/
# └── galleries/ # From backup galleries/ (if any)
# 4. Start containers
docker-compose up -d
# 5. Access Piwigo at http://localhost:8080
```
## Directory Structure
```
ep-piwigo-docker/
├── Dockerfile # Custom image with mariadb-client, fixed PHP settings
├── docker-entrypoint.sh # Handles permissions, DB wait
├── docker-compose.yml # MariaDB + Piwigo services
├── .env.example # Environment template
└── piwigo-data/ # Your data (create this)
├── upload/
├── local/config/
└── galleries/
```
## Restore from Backup
After running the restore script on the Docker host, your data will be in `../piwigo-data/`. You can either:
**Option A: Use this directory directly**
```bash
# Symlink or copy to ./piwigo-data
ln -s ../piwigo-data ./piwigo-data
docker-compose up -d
```
**Option B: Copy to this directory**
```bash
cp -r ../piwigo-data/* ./piwigo-data/
docker-compose up -d
```
## Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| `DB_ROOT_PASS` | MariaDB root password | **required** |
| `DB_NAME` | Database name | `piwigo` |
| `DB_USER` | Database user | `piwigo` |
| `DB_PASS` | Database user password | **required** |
| `PIWIGO_DATA_DIR` | Host data directory | `./piwigo-data` |
| `PIWIGO_PORT` | Host port for web UI | `8080` |
## Custom Entrypoint Features
The custom `docker-entrypoint.sh`:
- Fixes permissions on upload/, config/, galleries/ directories
- Waits for database to be ready before starting Apache
- Extracts DB config from existing config.inc.php if present
## Database
Uses MariaDB 10.11. Data persisted in Docker volume `db-data`.
## Health Checks
Both services have health checks:
- MariaDB: `mysqladmin ping`
- Piwigo: Depends on healthy DB
## Logs
```bash
# View Piwigo logs
docker-compose logs -f piwigo
# View DB logs
docker-compose logs -f db
```
## Stopping
```bash
docker-compose down
```
## Backup (Docker-side)
```bash
# Backup database
docker-compose exec db mariadb-dump -u root -p"$DB_ROOT_PASS" piwigo > backup_$(date +%Y%m%d).sql
# Backup files
tar -czf piwigo_files_$(date +%Y%m%d).tar.gz piwigo-data/
```
+52
View File
@@ -0,0 +1,52 @@
version: '3.8'
services:
db:
image: mariadb:10.11
container_name: ep-piwigo-db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS}
MYSQL_DATABASE: ${DB_NAME:-piwigo}
MYSQL_USER: ${DB_USER:-piwigo}
MYSQL_PASSWORD: ${DB_PASS}
volumes:
- db-data:/var/lib/mysql
networks:
- piwigo-net
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
piwigo:
build: .
container_name: ep-piwigo
restart: unless-stopped
depends_on:
db:
condition: service_healthy
environment:
DB_HOST: db
DB_PORT: 3306
DB_NAME: ${DB_NAME:-piwigo}
DB_USER: ${DB_USER:-piwigo}
DB_PASS: ${DB_PASS}
PHP_MEMORY_LIMIT: 512M
PHP_MAX_EXECUTION_TIME: 300
PHP_UPLOAD_MAX_FILESIZE: 100M
PHP_POST_MAX_SIZE: 100M
volumes:
- ${PIWIGO_DATA_DIR:-./piwigo-data}:/var/www/html
ports:
- "${PIWIGO_PORT:-8080}:80"
networks:
- piwigo-net
volumes:
db-data:
networks:
piwigo-net:
driver: bridge
+47
View File
@@ -0,0 +1,47 @@
#!/bin/bash
# Custom entrypoint for Piwigo Docker container
# Handles restore initialization and permission fixes
set -e
# Fix permissions on mounted volumes
if [ -d "/var/www/html/upload" ]; then
chown -R www-data:www-data /var/www/html/upload 2>/dev/null || true
find /var/www/html/upload -type d -exec chmod 755 {} \; 2>/dev/null || true
find /var/www/html/upload -type f -exec chmod 644 {} \; 2>/dev/null || true
fi
if [ -d "/var/www/html/local/config" ]; then
chown -R www-data:www-data /var/www/html/local/config 2>/dev/null || true
find /var/www/html/local/config -type f -exec chmod 644 {} \; 2>/dev/null || true
fi
if [ -d "/var/www/html/galleries" ]; then
chown -R www-data:www-data /var/www/html/galleries 2>/dev/null || true
find /var/www/html/galleries -type d -exec chmod 755 {} \; 2>/dev/null || true
find /var/www/html/galleries -type f -exec chmod 644 {} \; 2>/dev/null || true
fi
# If config exists but no database, wait for DB
if [ -f "/var/www/html/local/config/config.inc.php" ]; then
echo "Config found, checking database connection..."
# Extract DB config from config.inc.php
DB_HOST=$(grep -oP "'db_host'\s*=>\s*'\K[^']+" /var/www/html/local/config/config.inc.php 2>/dev/null || echo "db")
DB_USER=$(grep -oP "'db_user'\s*=>\s*'\K[^']+" /var/www/html/local/config/config.inc.php 2>/dev/null || echo "piwigo")
DB_PASS=$(grep -oP "'db_password'\s*=>\s*'\K[^']+" /var/www/html/local/config/config.inc.php 2>/dev/null || echo "")
DB_NAME=$(grep -oP "'db_name'\s*=>\s*'\K[^']+" /var/www/html/local/config/config.inc.php 2>/dev/null || echo "piwigo")
# Wait for database
for i in {1..30}; do
if mariadb -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" -e "SELECT 1" "$DB_NAME" >/dev/null 2>&1; then
echo "Database connection successful"
break
fi
echo "Waiting for database... ($i/30)"
sleep 2
done
fi
# Execute original entrypoint
exec /usr/local/bin/docker-entrypoint.sh "$@"