selfhosted-apps-docker/bookstack/readme.md

250 lines
7.5 KiB
Markdown
Raw Permalink Normal View History

2020-04-09 22:52:11 +00:00
# Bookstack in docker
2020-05-18 22:49:18 +00:00
###### guide-by-example
2020-04-09 22:52:11 +00:00
![logo](https://i.imgur.com/qDXwqaU.png)
2020-05-06 23:13:02 +00:00
# Purpose & Overview
2020-04-09 22:52:11 +00:00
Documentation and notes.
* [Official site](https://www.bookstackapp.com/)
* [Github](https://github.com/BookStackApp/BookStack)
2020-04-10 02:40:54 +00:00
* [DockerHub](https://hub.docker.com/r/linuxserver/bookstack)
2020-04-09 22:52:11 +00:00
2020-05-06 23:13:02 +00:00
BookStack is a modern, open source, good looking wiki platform
2022-11-05 08:53:18 +00:00
for storing and organizing information.
2020-05-06 23:13:02 +00:00
2023-02-11 22:36:00 +00:00
Written in PHP, using Laravel framework, with MySQL database for the user data.</br>
2020-05-07 19:45:04 +00:00
There is no official Dockerhub image so the one maintained by
2020-05-06 23:13:02 +00:00
[linuxserver.io](https://www.linuxserver.io/) is used,
which uses nginx as a web server.
2020-04-24 22:52:32 +00:00
# Files and directory structure
2020-04-09 22:52:11 +00:00
2020-04-25 22:49:11 +00:00
```
2020-05-01 09:38:43 +00:00
/home/
└── ~/
└── docker/
└── bookstack/
2023-02-12 08:11:41 +00:00
├── 🗁 bookstack_data/
├── 🗁 bookstack_db_data/
├── 🗋 .env
├── 🗋 docker-compose.yml
└── 🗋 bookstack-backup-script.sh
2020-04-25 22:49:11 +00:00
```
2020-04-09 22:52:11 +00:00
2023-02-12 14:16:18 +00:00
* `bookstack_data/` - a directory with bookstacks web app data
* `bookstack_db_data/` - a directory with database data
2020-05-22 16:05:03 +00:00
* `.env` - a file containing environment variables for docker compose
2020-05-22 16:22:45 +00:00
* `docker-compose.yml` - a docker compose file, telling docker how to run the containers
2023-02-12 08:11:41 +00:00
* `bookstack-backup-script.sh` - a backup script, to be run daily
2020-05-07 19:45:04 +00:00
2023-02-12 14:16:18 +00:00
Only the files are required. The directories are created on the first run.
2020-05-07 19:45:04 +00:00
2020-04-24 22:52:32 +00:00
# docker-compose
2020-04-09 22:52:11 +00:00
2020-05-01 09:51:20 +00:00
Dockerhub linuxserver/bookstack
[example compose.](https://hub.docker.com/r/linuxserver/bookstack)
2020-04-25 22:49:11 +00:00
`docker-compose.yml`
```yml
services:
bookstack-db:
image: linuxserver/mariadb
container_name: bookstack-db
hostname: bookstack-db
restart: unless-stopped
env_file: .env
volumes:
2023-02-11 22:24:59 +00:00
- ./bookstack_db_data:/config
2023-06-24 18:11:52 +00:00
ports:
- "3306:3306"
2020-04-25 22:49:11 +00:00
bookstack:
image: linuxserver/bookstack
container_name: bookstack
hostname: bookstack
restart: unless-stopped
env_file: .env
depends_on:
- bookstack-db
volumes:
2023-02-11 22:24:59 +00:00
- ./bookstack_data:/config
2023-06-24 18:11:52 +00:00
ports:
- "80:80"
2020-04-25 22:49:11 +00:00
networks:
default:
2023-02-11 22:24:59 +00:00
name: $DOCKER_MY_NETWORK
external: true
2020-04-25 22:49:11 +00:00
```
`.env`
```bash
# GENERAL
2020-05-20 18:29:12 +00:00
DOCKER_MY_NETWORK=caddy_net
2020-05-02 20:48:23 +00:00
TZ=Europe/Bratislava
2020-04-25 22:49:11 +00:00
#LINUXSERVER.IO
PUID=1000
PGID=1000
# BOOKSTACK-MARIADB
MYSQL_ROOT_PASSWORD=bookstack
MYSQL_DATABASE=bookstack
MYSQL_USER=bookstack
MYSQL_PASSWORD=bookstack
# BOOKSTACK
2020-05-20 17:20:01 +00:00
APP_URL=https://book.example.com
2020-04-25 22:49:11 +00:00
DB_HOST=bookstack-db
DB_USER=bookstack
DB_PASS=bookstack
DB_DATABASE=bookstack
2023-02-11 22:24:59 +00:00
# USING SENDINBLUE FOR SENDING EMAILS
2020-04-25 22:49:11 +00:00
MAIL_DRIVER=smtp
2023-02-11 22:24:59 +00:00
MAIL_ENCRYPTION=tls
MAIL_HOST=smtp-relay.sendinblue.com
MAIL_PORT=587
2020-05-16 13:18:21 +00:00
MAIL_FROM=book@example.com
2023-02-11 22:24:59 +00:00
MAIL_USERNAME=<registration-email@gmail.com>
2023-02-12 08:11:41 +00:00
MAIL_PASSWORD=<sendinblue-smtp-key-goes-here>
2020-04-25 22:49:11 +00:00
```
**All containers must be on the same network**.</br>
2020-05-10 21:48:51 +00:00
Which is named in the `.env` file.</br>
2020-04-25 22:49:11 +00:00
If one does not exist yet: `docker network create caddy_net`
2020-04-10 23:51:47 +00:00
2023-02-12 18:06:15 +00:00
`APP_URL` in the `.env` **must be set** for bookstack to work.<br>
2023-02-12 14:23:21 +00:00
`MAIL_` stuff must be set for password reset and new registrations.
2020-04-24 22:52:32 +00:00
# Reverse proxy
2020-04-09 22:52:11 +00:00
2020-05-01 09:51:20 +00:00
Caddy v2 is used, details
[here](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/caddy_v2).</br>
2020-04-09 22:52:11 +00:00
2020-04-25 22:49:11 +00:00
`Caddyfile`
2023-02-12 14:16:18 +00:00
```php
2020-04-25 22:49:11 +00:00
book.{$MY_DOMAIN} {
reverse_proxy bookstack:80
}
```
2020-04-09 22:52:11 +00:00
2020-05-20 17:15:19 +00:00
# First run
Default login: `admin@admin.com` // `password`
2020-04-16 22:05:54 +00:00
---
2020-04-10 23:51:47 +00:00
![interface-pic](https://i.imgur.com/cN1GUZw.png)
2020-04-09 22:52:11 +00:00
2022-04-03 08:50:12 +00:00
# Trouble shooting
2023-02-12 00:11:29 +00:00
* It did not start.<br>
Ctrl+f in `.env` file for word `example` to be replaced with actual domain
name. `APP_URL` has to be set correctly for bookstack to work.
2023-02-12 08:11:41 +00:00
* After update cant see edit tools.<br>
Clear browsers cookies/cache.
* The test email button in preferences throws error.<br>
Exec in to the container and `printenv` to see.
Check [mail.php](https://github.com/BookStackApp/BookStack/blob/development/app/Config/mail.php)
to see exact `MAIL_` env variables names and default values.
2023-02-12 08:23:42 +00:00
Test in Thunderbird your smtp server working or not.
2022-04-03 08:50:12 +00:00
2020-04-24 22:52:32 +00:00
# Update
2020-04-10 02:40:54 +00:00
2020-05-09 00:49:15 +00:00
Manual image update:
- `docker-compose pull`</br>
- `docker-compose up -d`</br>
- `docker image prune`
2020-04-09 22:52:11 +00:00
2023-02-12 18:06:15 +00:00
It is **strongly recommended** to now add current **tags** to the images in the compose.<br>
Tags will allow you to easily return to a working state if an update goes wrong.
If there was a **major version jump**, and bookstack does not work,
exec in to the app container and run php artisan migrate</br>
`docker container exec -it bookstack /bin/bash`</br>
`cd /app/www`</br>
`php artisan migrate`
2023-02-11 22:24:59 +00:00
2020-04-24 22:52:32 +00:00
# Backup and restore
2020-04-09 22:52:11 +00:00
2020-05-07 19:45:04 +00:00
#### Backup
2023-02-11 22:36:00 +00:00
Using [kopia](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/kopia_backup)
or [borg](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/borg_backup)
to make daily snapshot of the entire docker directory.
2020-05-07 19:45:04 +00:00
#### Restore
2023-02-12 18:06:15 +00:00
* down the containers `docker-compose down`</br>
* delete/move/rename the entire project directory</br>
* from the backups copy back the entire project directory</br>
2020-05-07 19:45:04 +00:00
* start the containers `docker-compose up -d`
2020-04-09 22:52:11 +00:00
2020-04-24 22:52:32 +00:00
# Backup of just user data
2020-04-09 22:52:11 +00:00
2020-05-07 19:45:04 +00:00
Users data daily export using the
[official procedure.](https://www.bookstackapp.com/docs/admin/backup-restore/)</br>
2020-04-24 22:52:32 +00:00
For bookstack it means database dump and backing up several directories
containing user uploaded files.
2023-02-12 08:11:41 +00:00
Daily kopia/borg backup run takes care of backing up the directories.
So only database dump is needed and done with the script.</br>
The created backup sql file is overwritten on every run of the script,
2023-02-11 22:36:00 +00:00
but that's ok since kopia/borg are keeping daily snapshots.
2020-05-07 19:45:04 +00:00
2023-02-12 08:11:41 +00:00
#### Backup script
2020-04-09 22:52:11 +00:00
2020-05-07 19:45:04 +00:00
Placed inside `bookstack` directory on the host
`bookstack-backup-script.sh`
```bash
#!/bin/bash
# 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'
```
2020-04-09 22:52:11 +00:00
2020-05-07 19:45:04 +00:00
the script must be **executable** - `chmod +x bookstack-backup-script.sh`
2020-04-09 22:52:11 +00:00
2023-02-12 08:11:41 +00:00
#### Cronjob - scheduled backup
2020-04-09 22:52:11 +00:00
2023-02-12 08:11:41 +00:00
Running on the host
2020-04-09 22:52:11 +00:00
2020-05-07 19:45:04 +00:00
* `su` - switch to root
* `crontab -e` - add new cron job</br>
* `0 22 * * * /home/bastard/docker/bookstack/bookstack-backup-script.sh`</br>
runs it every day [at 22:00](https://crontab.guru/#0_22_*_*_*)
* `crontab -l` - list cronjobs to check
2020-04-09 22:52:11 +00:00
2020-04-24 22:52:32 +00:00
# Restore the user data
2020-04-09 22:52:11 +00:00
2023-02-12 08:11:41 +00:00
Assuming clean start and latest images.<br>
Will need `BACKUP.bookstack.database.sql` and content of `bookstack_data/www/`<br>
Note that database restore must happen before bookstack app is first run.
2020-05-07 19:45:04 +00:00
* start only the database container: `docker-compose up -d bookstack-db`
2023-02-11 22:24:59 +00:00
* copy `BACKUP.bookstack.database.sql` in `bookstack/bookstack_db_data/`
2020-05-07 19:45:04 +00:00
* restore the database inside the container</br>
`docker container exec --workdir /config bookstack-db bash -c 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE < BACKUP.bookstack.database.sql'`
* now start the app container: `docker-compose up -d`
* let it run so it creates its file structure
* down the containers `docker-compose down`
2023-02-11 22:24:59 +00:00
* in `bookstack/bookstack_data/www/`</br>
2020-05-07 19:45:04 +00:00
replace directories `files`,`images`,`uploads` and the file `.env`</br>
with the ones from the BorgBackup repository
* start the containers: `docker-compose up -d`
* if there was a major version jump, exec in to the app container and run `php artisan migrate`</br>
`docker container exec -it bookstack /bin/bash`</br>
2023-02-12 00:11:29 +00:00
`cd /app/www`</br>
2020-05-07 19:45:04 +00:00
`php artisan migrate`
Again, the above steps are based on the
2023-02-11 22:24:59 +00:00
[official procedure](https://www.bookstackapp.com/docs/admin/backup-restore/)
2023-02-12 08:23:42 +00:00
at the time of writing this.