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.

210 lines
5.9 KiB
Markdown

4 years ago
# Bookstack in docker
###### guide by example
![logo](https://i.imgur.com/qDXwqaU.png)
### Purpose
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
### Files and directory structure
```
/home
└── ~
└── docker
└── bookstack
├── 🗁 bookstack-data
├── 🗁 bookstack-data-db
├── 🗋 .env
├── 🗋 docker-compose.yml
└── 🗋 bookstack-backup-script.sh
```
### docker-compose
Dockerhub linuxserver/bookstack [example compose.](https://hub.docker.com/r/linuxserver/bookstack)
`docker-compose.yml`
```
version: "2"
services:
4 years ago
bookstack_db:
image: linuxserver/mariadb
container_name: bookstack_db
hostname: bookstack_db
environment:
- TZ
- PUID
- PGID
- MYSQL_ROOT_PASSWORD
- MYSQL_DATABASE
- MYSQL_USER
- MYSQL_PASSWORD
volumes:
- ./bookstack-data-db:/config
restart: unless-stopped
4 years ago
bookstack:
image: linuxserver/bookstack
container_name: bookstack
hostname: bookstack
environment:
4 years ago
- TZ
4 years ago
- PUID
- PGID
- DB_HOST
- DB_USER
- DB_PASS
- DB_DATABASE
- APP_URL
4 years ago
- MAIL_DRIVER
- MAIL_HOST
- MAIL_PORT
- MAIL_FROM
- MAIL_USERNAME
- MAIL_PASSWORD
- MAIL_ENCRYPTION
4 years ago
volumes:
- ./bookstack-data:/config
restart: unless-stopped
depends_on:
- bookstack_db
networks:
default:
external:
name: $DEFAULT_NETWORK
```
`.env`
```
# GENERAL
MY_DOMAIN=blabla.org
DEFAULT_NETWORK=caddy_net
TZ=Europe/Prague
4 years ago
# BOOKSTACK-MARIADB
PUID=1000
PGID=1000
MYSQL_ROOT_PASSWORD=bookstack
MYSQL_DATABASE=bookstack
MYSQL_USER=bookstack
MYSQL_PASSWORD=bookstack
4 years ago
# BOOKSTACK
PUID=1000
PGID=1000
DB_HOST=bookstack_db
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
### 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} {
reverse_proxy {
to bookstack:80
}
}
```
4 years ago
![logo](https://i.imgur.com/cN1GUZw.png)
4 years ago
4 years ago
### Update
* [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`
### Backup of just user data
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
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>
`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`