实战教程:利用Docker容器化技术部署Szurubooru图像分享平台
- 一、Szurubooru介绍
- 1.1 Szurubooru简介
- 1.2 主要特点
- 1.3 主要使用场景
- 二、本次实践规划
- 2.1 本地环境规划
- 2.2 本次实践介绍
- 三、本地环境检查
- 3.1 检查Docker服务状态
- 3.2 检查Docker版本
- 3.3 检查docker compose 版本
- 四、下载Szurubooru镜像
- 五、部署Szurubooru应用
- 5.1 创建部署目录
- 5.2 编辑config.yaml文件
- 5.3 编辑.env文件
- 5.4 编辑部署文件
- 5.5 创建Szurubooru容器
- 5.6 查看Szurubooru容器状态
- 5.7 查Szurubooru容器日志
- 六、访问Szurubooru服务
- 6.1 访问Szurubooru初始页
- 6.2 注册账号
- 6.3 上传图片
- 七、总结
一、Szurubooru介绍
1.1 Szurubooru简介
Szurubooru
提供了一个强大而灵活的平台,让社区成员可以上传、分享、讨论以及管理多媒体内容。它支持多种媒体格式,并提供了一系列工具来帮助用户组织和发现内容。该平台特别适合那些需要高度定制化和控制自己内容存储与展示方式的小众爱好者群体。
1.2 主要特点
- 发布内容:支持图片(JPG, PNG, GIF, 动态GIF)、视频(MP4, WEBM)及Flash动画。
- 网络视频抓取:能够使用 yt-dlp 工具从互联网上获取视频内容。
- 评论功能:允许用户对发布的每项内容添加评论。
- 注释/标注:支持在图片上添加注释,包括自定义多边形区域。
- REST API:提供丰富的JSON REST API接口,便于开发者集成。
- 客户端认证:基于令牌的认证机制保障了客户端的安全访问。
- 搜索系统:强大的搜索能力,可以根据标签等信息快速找到相关内容。
- 权限系统:精细的权限设置确保了不同角色用户对内容的不同访问级别。
- 自动补全:在搜索或编辑标签时提供智能提示。
- 标签分类:支持对标签进行分组归类。
- 标签建议:根据上下文给出可能相关的标签推荐。
- 标签关联:当添加某个标签时自动关联其他相关标签。
- 标签别名:允许设定标签别名以提高查找效率。
- 集合及其类别:方便地将相似主题的内容组织成集合并分类。
- 重复检测:自动识别并标记出潜在的重复内容。
- 评分与收藏:用户可以对自己喜欢的内容打分或将它们加入个人收藏夹。
- 用户界面:拥有精致美观的操作界面。
- 浏览器配置选项:支持无尽滚动浏览模式及透明图片背景网格设置。
1.3 主要使用场景
- 兴趣小组:适合动漫迷、艺术家、摄影师等特定兴趣爱好的小圈子使用,作为交流与分享作品的空间。
- 教育用途:教师可以利用此平台收集教学资源,学生则可以通过浏览学习到更多知识。
- 私人收藏:对于想要建立自己的数字藏品库的人来说,这是一个非常好的解决方案,无论是艺术品还是珍贵照片都可以妥善保存并轻松检索。
- 研究项目:研究人员可借助 Szurubooru 来管理和分析大量视觉资料,比如历史档案、科学图像等。
- 企业内部:公司内部也可以部署这样一个系统用来存放产品图片、广告素材等商业资料,并且通过严格的权限控制保证信息安全。
二、本次实践规划
2.1 本地环境规划
本次实践为个人测试环境,操作系统版本为|Ubuntu 22.04.1。
hostname | IP地址 | 操作系统版本 | 内核版本 | Docker版本 | 镜像版本 |
---|---|---|---|---|---|
jeven01 | 192.168.3.88 | Ubuntu 22.04.1 LTS | 5.15.0-119-generic | 24.0.7 | 2.5 |
2.2 本次实践介绍
1.本次实践部署环境为个人测试环境,生产环境请谨慎;
2.在Docker环境下部署Szurubooru图像板应用。
三、本地环境检查
3.1 检查Docker服务状态
检查Docker服务是否正常运行,确保Docker正常运行。
root@ubuntu-001:~# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2024-09-29 08:29:36 UTC; 18min ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 5227 (dockerd)
Tasks: 123
Memory: 272.5M
CPU: 9.692s
CGroup: /system.slice/docker.service
├─5227 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
3.2 检查Docker版本
检查Docker版本
root@ubuntu-001:~# docker -v
Docker version 24.0.7, build 24.0.7-0ubuntu2~22.04.1
3.3 检查docker compose 版本
检查Docker compose版本,确保2.0以上版本。
root@ubuntu-001:~# docker compose version
Docker Compose version v2.19.1
四、下载Szurubooru镜像
拉取Szurubooru镜像,其中镜像szurubooru两个镜像版本使用的为2.5。
docker pull szurubooru/server:2.5
docker pull szurubooru/client:2.5
docker pull postgres:11-alpine
五、部署Szurubooru应用
5.1 创建部署目录
- 创建部署目录
mkdir -p /data/szurubooru && cd /data/szurubooru
- 设置目录权限
chmod -R 777 /data/szurubooru/
5.2 编辑config.yaml文件
编辑config.yaml配置文件,内容所辖:
vim config.yaml
# rather than editing this file, it is strongly suggested to create config.yaml
# and override only what you need.
# shown in the website title and on the front page
name: szurubooru
# full url to the homepage of this szurubooru site, with no trailing slash
domain: # example: http://example.com
# used to salt the users' password hashes and generate filenames for static content
secret: change
# Delete thumbnails and source files on post delete
# Original functionality is no, to mitigate the impacts of admins going
# on unchecked post purges.
delete_source_files: no
thumbnails:
avatar_width: 300
avatar_height: 300
post_width: 300
post_height: 300
# settings used to download files from the web on behalf of the api users
user_agent:
max_dl_filesize: 25.0E+6 # maximum filesize limit in bytes
# automatically convert animated GIF uploads to video formats
convert:
gif:
to_webm: false
to_mp4: false
# allow posts to be uploaded even if some image processing errors occur
allow_broken_uploads: false
# used to send password reset e-mails
smtp:
host: # example: localhost
port: # example: 25
user: # example: bot
pass: # example: groovy123
from: # example: noreply@example.com
# if host is left empty the password reset feature will be disabled,
# in which case it is recommended to fill contactEmail so that users
# know who to contact when they want to reset their password
contact_email: # example: bob@example.com. Meant for manual password reset procedures
enable_safety: yes
tag_name_regex: ^\S+$
tag_category_name_regex: ^[^\s%+#/]+$
pool_name_regex: ^\S+$
pool_category_name_regex: ^[^\s%+#/]+$
# don't make these more restrictive unless you want to annoy people; if you do
# customize them, make sure to update the instructions in the registration form
# template as well.
password_regex: '^.{5,}$'
user_name_regex: '^[a-zA-Z0-9_-]{1,32}$'
# webhooks to call when events occur (such as post/tag/user/etc. changes)
# the listed urls will be called with a HTTP POST request with a payload
# containing a snapshot resource as JSON. See doc/API.md for details
webhooks:
# - https://api.example.com/webhooks/
default_rank: regular
privileges:
'users:create:self': anonymous # Registration permission
'users:create:any': administrator
'users:list': regular
'users:view': regular
'users:edit:any:name': moderator
'users:edit:any:pass': moderator
'users:edit:any:email': moderator
'users:edit:any:avatar': moderator
'users:edit:any:rank': moderator
'users:edit:self:name': regular
'users:edit:self:pass': regular
'users:edit:self:email': regular
'users:edit:self:avatar': regular
'users:edit:self:rank': moderator # one can't promote themselves or anyone to upper rank than their own.
'users:delete:any': administrator
'users:delete:self': regular
'user_tokens:list:any': administrator
'user_tokens:list:self': regular
'user_tokens:create:any': administrator
'user_tokens:create:self': regular
'user_tokens:edit:any': administrator
'user_tokens:edit:self': regular
'user_tokens:delete:any': administrator
'user_tokens:delete:self': regular
'posts:create:anonymous': regular
'posts:create:identified': regular
'posts:list': anonymous
'posts:reverse_search': regular
'posts:view': anonymous
'posts:view:featured': anonymous
'posts:edit:content': power
'posts:edit:flags': regular
'posts:edit:notes': regular
'posts:edit:relations': regular
'posts:edit:safety': power
'posts:edit:source': regular
'posts:edit:tags': regular
'posts:edit:thumbnail': power
'posts:feature': moderator
'posts:delete': moderator
'posts:score': regular
'posts:merge': moderator
'posts:favorite': regular
'posts:bulk-edit:tags': power
'posts:bulk-edit:safety': power
'posts:bulk-edit:delete': power
'tags:create': regular
'tags:edit:names': power
'tags:edit:category': power
'tags:edit:description': power
'tags:edit:implications': power
'tags:edit:suggestions': power
'tags:list': regular
'tags:view': anonymous
'tags:merge': moderator
'tags:delete': moderator
'tag_categories:create': moderator
'tag_categories:edit:name': moderator
'tag_categories:edit:color': moderator
'tag_categories:edit:order': moderator
'tag_categories:list': anonymous
'tag_categories:view': anonymous
'tag_categories:delete': moderator
'tag_categories:set_default': moderator
'pools:create': regular
'pools:edit:names': power
'pools:edit:category': power
'pools:edit:description': power
'pools:edit:posts': power
'pools:list': regular
'pools:view': anonymous
'pools:merge': moderator
'pools:delete': moderator
'pool_categories:create': moderator
'pool_categories:edit:name': moderator
'pool_categories:edit:color': moderator
'pool_categories:list': anonymous
'pool_categories:view': anonymous
'pool_categories:delete': moderator
'pool_categories:set_default': moderator
'comments:create': regular
'comments:delete:any': moderator
'comments:delete:own': regular
'comments:edit:any': moderator
'comments:edit:own': regular
'comments:list': regular
'comments:view': regular
'comments:score': regular
'snapshots:list': power
'uploads:create': regular
'uploads:use_downloader': power
## ONLY SET THESE IF DEPLOYING OUTSIDE OF DOCKER
#debug: 0 # generate server logs?
#show_sql: 0 # show sql in server logs?
#data_url: /data/
#data_dir: /var/www/data
## usage: schema://user:password@host:port/database_name
## example: postgres://szuru:dog@localhost:5432/szuru_test
#database:
5.3 编辑.env文件
在部署目录下,新建及编辑.env文件
vim .env
# Database credentials
POSTGRES_USER=jeven
POSTGRES_PASSWORD=jeven
# This shows up on the homescreen, indicating build information
BUILD_INFO=latest
# Port to expose HTTP service
# Set to 127.0.0.1:8080 if you wish to reverse-proxy the docker's port,
# otherwise the port specified here will be publicly accessible
PORT=8080
# How many waitress threads to start
# 4 is the default amount of threads. If you experience performance
# degradation with a large number of posts, increasing this may
# improve performance, since waitress is most likely clogging up with Tasks.
THREADS=4
# URL base to run szurubooru under
# See "Additional Features" section in INSTALL.md
BASE_URL=/
# Directory to store image data
MOUNT_DATA=/data/szurubooru/data
# Directory to store database files
MOUNT_SQL=/data/szurubooru/sql
5.4 编辑部署文件
在/data/szurubooru`目录下,创建docker-compose.yaml文件,宿主机映射端口可自行修改,注意防止端口冲突。
vim docker-compose.yaml
## Example Docker Compose configuration
##
## Use this as a template to set up docker-compose, or as guide to set up other
## orchestration services
version: '2'
services:
server:
image: szurubooru/server:2.5
depends_on:
- sql
environment:
## These should be the names of the dependent containers listed below,
## or FQDNs/IP addresses if these services are running outside of Docker
POSTGRES_HOST: sql
## Credentials for database:
POSTGRES_USER:
POSTGRES_PASSWORD:
## Commented Values are Default:
#POSTGRES_DB: defaults to same as POSTGRES_USER
#POSTGRES_PORT: 5432
#LOG_SQL: 0 (1 for verbose SQL logs)
THREADS:
volumes:
- "${MOUNT_DATA}:/data"
- "./config.yaml:/opt/app/config.yaml"
client:
image: szurubooru/client:2.5
depends_on:
- server
environment:
BACKEND_HOST: server
BASE_URL:
volumes:
- "${MOUNT_DATA}:/data:ro"
ports:
- "${PORT}:80"
sql:
image: postgres:11-alpine
restart: unless-stopped
environment:
POSTGRES_USER:
POSTGRES_PASSWORD:
volumes:
- "${MOUNT_SQL}:/var/lib/postgresql/data"
5.5 创建Szurubooru容器
执行以下命令,创建Szurubooru容器。
root@jeven01:/data/szurubooru# docker compose up -d
[+] Running 4/4
✔ Network szurubooru_default Created 0.1s
✔ Container szurubooru-sql-1 Started 0.4s
✔ Container szurubooru-server-1 Started 0.6s
✔ Container szurubooru-client-1 Started 0.8s
5.6 查看Szurubooru容器状态
检查Szurubooru容器状态状态,确保Szurubooru容器正常启动。
root@jeven01:/data/szurubooru# docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
szurubooru-client-1 szurubooru/client:2.5 "/docker-entrypoint.…" client 36 seconds ago Up 35 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp
szurubooru-server-1 szurubooru/server:2.5 "/opt/app/docker-sta…" server 36 seconds ago Up 35 seconds 6666/tcp
szurubooru-sql-1 postgres:11-alpine "docker-entrypoint.s…" sql 37 seconds ago Up 36 seconds 5432/tcp
5.7 查Szurubooru容器日志
检查Szurubooru容器日志,确保Szurubooru服务正常运行。
root@jeven01:/data/szurubooru# docker compose logs
szurubooru-sql-1 |
szurubooru-sql-1 |
szurubooru-sql-1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
szurubooru-sql-1 |
szurubooru-sql-1 |
szurubooru-sql-1 | 2024-10-03 10:19:51.218 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
szurubooru-sql-1 | 2024-10-03 10:19:51.218 UTC [1] LOG: listening on IPv6 address "::", port 5432
szurubooru-sql-1 | 2024-10-03 10:19:51.221 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
szurubooru-sql-1 | 2024-10-03 10:19:51.235 UTC [22] LOG: database system was shut down at 2024-10-03 10:19:27 UTC
szurubooru-sql-1 | 2024-10-03 10:19:51.242 UTC [1] LOG: database system is ready to accept connections
szurubooru-server-1 | INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
szurubooru-server-1 | INFO [alembic.runtime.migration] Will assume transactional DDL.
szurubooru-server-1 | Starting szurubooru API on port 6666 - Running on 4 threads
六、访问Szurubooru服务
6.1 访问Szurubooru初始页
访问地址:http://192.168.3.88:8080,将IP替换为自己服务器IP地址。如果无法访问到以下页面,则检查宿主机的防火墙是否关闭或者放行相关端口,云服务器则还需要设置安全组规则。
6.2 注册账号
入下图所示,在菜单栏点击“
Register
”选项,注册账号。
自定义填写账号相关信息,确认注册即可。
6.3 上传图片
- 上传本地图片
- 预览图片效果
七、总结
在本次Docker项目实战中,我们成功运用Docker容器化技术部署了Szurubooru图像板应用,不仅实现了快速搭建和环境隔离,还显著提升了工作效率。通过Docker进行部署极大缩短了准备时间,同时保证了Szurubooru能够在多种环境中稳定运行。这一过程简化了应用的配置与管理,为开发者提供了极大的便利。鉴于其简便性和实用性,推荐对图像板感兴趣的朋友尝试使用Docker来部署Szurubooru。