Skip to main content

Bookstack - Docker Compose Stack with Nginx Reverse Proxy

413 words·
Bookstack Docker-Compose Nginx MariaDB
Table of Contents

Bookstack Docker Compose
#

Create User for Bookstack
#

# Create user for bookstack
sudo adduser --disabled-password bookstack

# Add user to Docker group
sudo usermod -aG docker bookstack


# List user ID
id bookstack

# Shell output:
uid=1001(bookstack) gid=1001(bookstack) groups=1001(bookstack)

Folder Structure
#

# Create folder structure
sudo mkdir -p /opt/bookstack/{bookstack_app_data,bookstack_db_data} && cd /opt/bookstack

# Change permissions
sudo chown -R 1001:1001 /opt/bookstack/{bookstack_app_data,bookstack_db_data}

Environment File
#

# Create environment file
sudo vi .env

# .env
PUID=1001
PGID=1001
APP_URL=https://bookstack.jklug.work
DB_HOST=bookstack_db
DB_PORT=3306
DB_USER=bookstack
DB_PASS=sqlpw # Define SQL pw
DB_DATABASE=bookstackapp

MYSQL_ROOT_PASSWORD=rootpw # Define root pw
TZ=Europe/London
MYSQL_DATABASE=bookstackapp
MYSQL_USER=bookstack
MYSQL_PASSWORD=sqlpw # Define SQL pw

Docker Compose File
#


# Create Docker Compose file
sudo vi docker-compose.yml

# docker-compose.yml
version: "2"
services:
  bookstack:
    image: lscr.io/linuxserver/bookstack
    container_name: bookstack
    env_file:
      - .env
    volumes:
      - ./bookstack_app_data:/config
    ports:
      - 6875:80
    restart: unless-stopped
    depends_on:
      - bookstack_db

  bookstack_db:
    image: lscr.io/linuxserver/mariadb
    container_name: bookstack_db
    env_file:
      - .env
    volumes:
      - ./bookstack_db_data:/config
    restart: unless-stopped

Start Container
#

# Create / start Docker stack
sudo docker compose up -d

Reverse Proxy
#

Certbot
#

# Install Certbot
sudo apt install certbot -y

# Create certificate
sudo certbot certonly --standalone -d bookstack.jklug.work

Nginx
#

# Install nginx
sudo apt install nginx -y

# Copy default config
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/bookstack.jklug.work
# Edit config
sudo vi /etc/nginx/sites-available/bookstack.jklug.work

# bookstack.jklug.work
server {
    listen 443 ssl;
    server_name bookstack.jklug.work;

    ssl_certificate         /etc/letsencrypt/live/bookstack.jklug.work/fullchain.pem;
    ssl_certificate_key     /etc/letsencrypt/live/bookstack.jklug.work/privkey.pem;


    location / {
        proxy_pass http://127.0.0.1:6875/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
# Disable default config
sudo rm /etc/nginx/sites-enabled/default

# Enable config
sudo ln -s /etc/nginx/sites-available/bookstack.jklug.work /etc/nginx/sites-enabled/

# Restart Nginx
sudo systemctl restart nginx

Bookstack
#

Bookstack Login
#

# Open GUI
https://bookstack.jklug.work/login

# Default User & PW
User: admin@admin.com
PW: password

Create Admin User from CLI
#

# Exec Container terminal
sudo docker exec -it bookstack bash

# Open directory
cd /app/www/

Note: Older Docker images may use /var/www/html/

# Create new Admin user: Prompts for name, email & pw
php artisan bookstack:create-admin

# Create new Admin user: Define name, email & pw
php artisan bookstack:create-admin --email="new-admin@domain.com" --name="new-admin" --password="password"
# Shell output:
Admin account with email "new-admin@domain.com" successfully created!

Bookstack Backup
#

# Exec Container terminal
sudo docker exec -it bookstack bash

# Open directory
cd /app/www/
# Create backup: Custom name
php ./bookstack-system-cli backup /app/www/storage/backups/daily-backup.zip

# Backup path on host
ls /opt/bookstack/bookstack_app_data/backups


# Create backup: Auto name with date and time
php ./bookstack-system-cli backup
# Shell output:
Output ZIP saved to: /app/www/storage/backups/bookstack-backup-2023-12-07-222254.zip

Links #

# Github Repo: 
https://github.com/linuxserver/docker-bookstack

# Admin commands:
https://www.bookstackapp.com/docs/admin/commands/

# CLI:
https://www.bookstackapp.com/docs/admin/system-cli/