You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
5.6 KiB
Markdown

4 years ago
# Bookstack in docker
###### guide by example
![logo](https://i.imgur.com/qDXwqaU.png)
4 years ago
## Purpose
4 years ago
Documentation and notes.
* [Official site](https://www.bookstackapp.com/)
* [Github](https://github.com/BookStackApp/BookStack)
4 years ago
* [DockerHub](https://hub.docker.com/r/linuxserver/bookstack)
4 years ago
4 years ago
## Files and directory structure
4 years ago
```
/home
└── ~
└── docker
└── bookstack
├── 🗁 bookstack-data
4 years ago
├── 🗁 bookstack-db-data
4 years ago
├── 🗋 .env
├── 🗋 docker-compose.yml
└── 🗋 bookstack-backup-script.sh
```
4 years ago
## docker-compose
4 years ago
Dockerhub linuxserver/bookstack [example compose.](https://hub.docker.com/r/linuxserver/bookstack)
`docker-compose.yml`
```
version: "2"
services:
4 years ago
bookstack-db:
4 years ago
image: linuxserver/mariadb
4 years ago
container_name: bookstack-db
hostname: bookstack-db
4 years ago
restart: unless-stopped
4 years ago
env_file: .env
volumes:
- ./bookstack-db-data:/config
4 years ago
4 years ago
bookstack:
image: linuxserver/bookstack
container_name: bookstack
hostname: bookstack
restart: unless-stopped
4 years ago
env_file: .env
4 years ago
depends_on:
4 years ago
- bookstack-db
4 years ago
volumes:
- ./bookstack-data:/config
4 years ago
networks:
default:
external:
name: $DEFAULT_NETWORK
```
`.env`
```
# GENERAL
MY_DOMAIN=blabla.org
DEFAULT_NETWORK=caddy_net
TZ=Europe/Prague
4 years ago
#LINUXSERVER.IO
4 years ago
PUID=1000
PGID=1000
4 years ago
# BOOKSTACK-MARIADB
4 years ago
MYSQL_ROOT_PASSWORD=bookstack
MYSQL_DATABASE=bookstack
MYSQL_USER=bookstack
MYSQL_PASSWORD=bookstack
4 years ago
# BOOKSTACK
4 years ago
DB_HOST=bookstack-db
4 years ago
DB_USER=bookstack
DB_PASS=bookstack
4 years ago
DB_DATABASE=bookstack
4 years ago
4 years ago
# USING SENDGRID FOR SENDING EMAILS
APP_URL=https://book.blabla.org
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=465
MAIL_FROM=book@blabla.org
MAIL_USERNAME=apikey
MAIL_PASSWORD=SG.2FA24asaddasdasdasdsadasdasdassadDEMBzuh9e43
MAIL_ENCRYPTION=SSL
4 years ago
```
4 years ago
**All containers must be on the same network**.</br>
If one does not exist yet: `docker network create caddy_net`
4 years ago
## Reverse proxy
4 years ago
4 years ago
Caddy v2 is used,
4 years ago
details [here](https://github.com/DoTheEvo/Caddy-v2-examples)
`Caddyfile`
```
{
# acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}
book.{$MY_DOMAIN} {
4 years ago
reverse_proxy bookstack:80
4 years ago
}
```
4 years ago
---
4 years ago
![interface-pic](https://i.imgur.com/cN1GUZw.png)
4 years ago
4 years ago
## Update
4 years ago
* [watchtower](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/watchtower) updates the image automaticly
4 years ago
* manual image update</br>
`docker-compose pull`</br>
`docker-compose up -d`</br>
`docker image prune`
4 years ago
## Backup and restore
4 years ago
4 years ago
* **backup** using [borgbackup setup](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/borg_backup)
4 years ago
that makes daily snapshot of the entire directory
4 years ago
* **restore**</br>
down the bookstack containers `docker-compose down`</br>
delete the entire bookstack directory</br>
from the backup copy back the bookstack directortory</br>
start the container `docker-compose up -d`
4 years ago
## Backup of just user data
4 years ago
4 years ago
user-data daily export using the [official procedure.](https://www.bookstackapp.com/docs/admin/backup-restore/)</br>
4 years ago
For bookstack it means database dump and backing up several directories containing user uploaded files.
The created backup files are overwriten on every run of the script,
but borg backup is daily making snapshot of the entire directory.
4 years ago
4 years ago
* **create a backup script**</br>
placed inside `bookstack` directory on the host
4 years ago
4 years ago
`bookstack-backup-script.sh`
4 years ago
```
4 years ago
#!/bin/bash
4 years ago
4 years ago
# CREATE DATABASE DUMP, bash -c '...' IS USED OTHERWISE OUTPUT > WOULD TRY TO GO TO THE HOST
4 years ago
docker container exec bookstack-db bash -c 'mysqldump -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE > $MYSQL_DIR/BACKUP.bookstack.database.sql'
4 years ago
4 years ago
# ARCHIVE UPLOADED FILES
docker container exec bookstack tar -czPf /config/BACKUP.bookstack.uploaded-files.tar.gz /config/www/
4 years ago
```
4 years ago
the script must be **executabe** - `chmod +x bookstack-backup-script.sh`
4 years ago
4 years ago
* **cronjob** on the host</br>
`crontab -e` - add new cron job</br>
`0 2 * * * /home/bastard/docker/bookstack/bookstack-backup-script.sh` - run it [at 02:00](https://crontab.guru/#0_2_*_*_*)</br>
`crontab -l` - list cronjobs
4 years ago
4 years ago
## Restore the user data
4 years ago
4 years ago
Assuming clean start, first restore the database before running the app container.
4 years ago
4 years ago
* start only the database container: `docker-compose up -d bookstack-db`
4 years ago
* have `BACKUP.bookstack.database.sql` mounted in by placing it in `bookstack/bookstack-data`
4 years ago
* exec in to the container and restore the database</br>
4 years ago
`docker container exec -it bookstack-db /bin/bash`</br>
4 years ago
`cd /config`</br>
4 years ago
`mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE < BACKUP.bookstack.database.sql`
4 years ago
* now start the app container: `docker-compose up -d`
* let it run so it creates its file structure
4 years ago
* down the containers `docker-compose down`
4 years ago
* in `bookstack/bookstack-data/www/` replace directories `files`,`images` and `uploads` and the file `.env`
with the ones from the archive `BACKUP.bookstack.uploaded-files.tar.gz`
4 years ago
* start the containers: `docker-compose up -d`
4 years ago
* if there was a major version jump, exec in to the app container and run `php artisan migrate`</br>
4 years ago
`docker container exec -it bookstack /bin/bash`</br>
`cd /var/www/html/`</br>
`php artisan migrate`