Guide to using Docker to build a Waline comment system
In this article, we’ll walk you through deploying the Waline commenting system using Docker and Docker Compose with an SQLite database. Waline is a lightweight, elegant commenting system that is suitable for integration into personal blogs. Here are the full steps.
Introduction
- Official Documentation: https://waline.js.org/guide/get-started/
- This tutorial uses Docker Compose for deployment.
- It is recommended to configure an SSL certificate for your domain (e.g. via Nginx or Certbot) to ensure security, especially in certain scenarios that require HTTPS.
Preparation
- Server Environment: A server running Linux (e.g. Ubuntu).
- Docker and Docker Compose: Make sure it’s installed.
Check Docker:
1docker --version
Check Docker Compose:
1docker-compose --version
If you do not install or encounter docker-compose urllib3 problems, please update docker-compose to the latest version, you can refer to the docker construction manual on this site to install;
Prepare the project catalog
Create a directory on the server to store Waline’s configuration files and data:
1mkdir -p ~/waline/data
2cd ~/waline
Write ‘docker-compose.yml’
Create a ‘docker-compose.yml’ file in the ‘~/waline’ directory:
1nano docker-compose.yml
Paste the following in and modify the configuration items as needed:
The following is a reference to [Steven Blog] (https://blog.stevenw.cc/archives/352WR9gB), thanks to Steven
1version: '3'
2services:
3 waline:
4 container_name: waline
5 image: lizheming/waline:latest
6 restart: always
7 ports:
8 - 8360:8360 #默认映射 `8360:8360`,可根据需要调整主机端口(例如 `3000:8360`)。
9 volumes:
10 - ${PWD}/data:/app/data # `${PWD}/data` 表示当前目录下的 `data` 文件夹,映射到容器内的 `/app/data`
11 environment:
12 TZ: 'Asia/Shanghai' # 时区
13 # SQLite 数据库配置
14 SQLITE_PATH: '/app/data' # 指定 SQLite 数据库文件路径。
15 JWT_TOKEN: '12345' # 用于 API 认证,务必设置为复杂值
16 # 站点基础配置
17 SITE_NAME: '你的博客名称' # 替换为你的博客名称
18 SITE_URL: 'https://your-domain.com' # 替换为你的博客 URL
19 SECURE_DOMAINS: 'your-domain.com' # 替换为你的域名
20 # 站长邮箱
21 AUTHOR_EMAIL: 'your-email@example.com' # 替换为你的邮箱
22 # SMTP 服务配置(可选,配置邮件通知,需根据你的邮箱服务商调整(例如 163、Gmail))博主未使用
23 #SMTP_SERVICE: '163' # SMTP 服务商,可选其他(如 Gmail)
24 #SMTP_USER: 'your-email@163.com' # 发件邮箱
25 #SMTP_PASS: 'your-smtp-password' # SMTP 密码或授权码
26 # 安全配置(可选)博主未使用
27 #IPQPS: '80' # 单 IP 评论频率限制
28 #COMMENT_AUDIT: 'true' # 是否需要审核评论
29 #AKISMET_KEY: 'your-akismet-key' # 反垃圾评论 Key(可选,需在 akismet.com 申请)
Save and exit (‘Ctrl O’, Enter, ‘Ctrl X’).
Download the initial SQLite file
Waline’s SQLite database requires a pre-initialized file rather than being created automatically. You can download it from the official website:
- Official description link: https://waline.js.org/guide/database.html#sqlite
- sqlite download link Download the ‘waline.sqlite’ file.
- Put the file into the data directory:
1mv ~/Downloads/waline.sqlite data/waline.sqlite
Note: Waline cannot automatically create a table without using the official ‘waline.sqlite’, and an error will be reported (such as ’no such table: wl_Comment’).
Start Waline
Run in the ‘~/waline’ directory:
1docker-compose up -d
- Check the container status:
1docker ps
You can see a container named ‘waline’ running.
- View logs:
1docker logs waline
If you see a message like ‘Server running at http://0.0.0.0:8360’, the startup was successful.
Verification Services
- Visit ‘http:// your server IP:8360’ in your browser and check if Waline responds properly.
- Register an administrator account: Visit ‘http:// your server IP: 8360/ui/register’ and follow the prompts to register the first user (who will become an administrator).
Integration to blogs
Add the following code to ‘hugo.yaml’:
1params:
2 comments: # 评论系统配置
3 enabled: true # 启用评论功能
4 provider: waline # 使用 Waline 作为评论提供者
5
6 waline: # Waline 配置
7 serverURL: https://你的服务区ip或url/ # Waline 服务器地址
8 lang: zh-cn # 评论语言,中文
9 pageview: true # 启用页面浏览量统计
10 emoji: # 表情包配置
11 - https://cdn.jsdelivr.net/gh/walinejs/emojis/weibo # 表情包路径
12 requiredMeta: # 必填字段
13 - name # 姓名
14 - email # 邮箱
15 locale: # 本地化设置
16 admin: 博主 # 管理员名称
17 placeholder: 🎉 留下你的脚印. # 输入框占位符
To rebuild and deploy the blog:
1cd /path/to/hugo-site
2hugo
3# Deploy public/ to the web server
The stack theme used by the blogger is supported by default, if the theme does not support Waline, manually add the client code to ’layouts/partials/footer.html’:
1<script src="//unpkg.com/@waline/client/dist/waline.js"></script>
2<div id="waline"></div>
3<script>
4 Waline.init({
5 el: '#waline',
6 serverURL: 'http:// your server stackIP: 8360 or url'
7 });
8</script>
Precautions
- SSL Certificate:
- For security reasons, it is recommended to configure HTTPS. You can use the Nginx reverse proxy and obtain the certificate through Certbot.
- Example Nginx configuration:
1server {
2 listen 80;
3 server_name your-domain.com;
4 location / {
5 proxy_pass http://localhost:8360;
6 proxy_set_header Host $host;
7 proxy_set_header X-Real-IP $remote_addr;
8 }
9}
- Data Backup:
Back up the ‘data/waline.db’ files regularly.
Troubleshooting
Error: ’no such table: wl_Comment’ or ’no such table: wl_User’: Make sure you are using the official ‘waline.sqlite’ file.
Unreachable: Check if the firewall has open ports:
1sudo ufw allow 8360