Add docker examples for restore services up
This commit is contained in:
@@ -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
|
||||
@@ -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"]
|
||||
@@ -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/
|
||||
```
|
||||
@@ -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
|
||||
@@ -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 "$@"
|
||||
Reference in New Issue
Block a user