How to Self-Host Your Own BookStack Knowledge Base with Docker
Knowledge is power. Whether you're a student, a professional, or simply someone who likes to organize their thoughts, a well-structured knowledge base can be transformative. In this guide, we’ll walk you through the steps to self-host BookStack using Docker for a streamlined and containerized deployment.
Why Choose BookStack?
BookStack is designed with simplicity and functionality in mind. It’s a great choice for creating a personal or organizational knowledge base. Here are some key features:
- Easy to Use: A clean, intuitive interface simplifies creating and editing content.
- Flexible Structure: Organize your knowledge base into books, chapters, and pages for easy navigation.
- Rich Formatting: Supports bold, italics, headings, lists, code blocks, and more for well-formatted content.
- File Attachments: Upload PDFs, images, spreadsheets, and other files directly to your pages.
- Search Functionality: Quickly find what you’re looking for with the built-in search feature.
- User Management: Set user roles and permissions for secure access control.
By self-hosting BookStack with Docker, you gain full control over your data and simplify deployment with containerization.
Prerequisites
Before we begin, ensure the following:
- A server with Docker and Docker Compose installed.
- Basic knowledge of Docker and server management.
- Domain name (optional but recommended for accessibility).
Step 1: Install Docker and Docker Compose
Start by installing Docker and Docker Compose on your server:
sudo apt update && sudo apt upgrade -y
sudo apt install docker.io docker-compose -y
Verify the installation:
docker --version
docker-compose --version
Step 2: Set Up a Docker Compose File
Create a new directory for your BookStack project:
mkdir bookstack && cd bookstack
Create a docker-compose.yml file:
nano docker-compose.yml
Add the following configuration:
services:
bookstack:
image: ghcr.io/linuxserver/bookstack:latest
container_name: bookstack
environment:
- PUID=1000
- PGID=1000
- APP_URL=http://yourdomain.com
- DB_HOST=bookstack_db
- DB_USER=bookstack
- DB_PASS=strongpassword
- DB_DATABASE=bookstack
volumes:
- ./data:/config
ports:
- 8080:80
depends_on:
- bookstack_db
bookstack_db:
image: mariadb:latest
container_name: bookstack_db
environment:
- MYSQL_ROOT_PASSWORD=strongpassword
- MYSQL_DATABASE=bookstack
- MYSQL_USER=bookstack
- MYSQL_PASSWORD=strongpassword
volumes:
- ./db:/var/lib/mysql
Replace yourdomain.com with your actual domain or server IP.
Step 3: Start the Containers
Run the following command to start the BookStack and database containers:
docker-compose up -d
Check the status of the containers:
docker-compose ps
Both the bookstack and bookstack_db services should be running.
Step 4: Configure Nginx as a Reverse Proxy (Optional)
If you want to use a custom domain or enable HTTPS, set up Nginx as a reverse proxy.
Install Nginx:
sudo apt install nginx -y
Create a new Nginx configuration file:
sudo nano /etc/nginx/sites-available/bookstack
Add the following content:
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Enable the site and restart Nginx:
sudo ln -s /etc/nginx/sites-available/bookstack /etc/nginx/sites-enabled/
sudo systemctl restart nginx
Step 5: Secure Your Installation with HTTPS
Install Certbot and the Nginx plugin:
sudo apt install certbot python3-certbot-nginx -y
Run Certbot to obtain an SSL certificate:
sudo certbot --nginx -d yourdomain.com
Follow the prompts to complete the setup.
Step 6: Access Your BookStack Instance
Open your browser and navigate to http://yourdomain.com (or https://yourdomain.com if HTTPS is enabled). You should see the BookStack setup page. Create an admin account and start building your knowledge base.
Conclusion
Congratulations! You’ve successfully set up your own self-hosted BookStack instance using Docker. This approach simplifies deployment and management while giving you full control over your knowledge base.
For more self-hosting guides and tips, stay tuned to madops.dev.