實戰(zhàn)教程:利用docker容器化技術(shù)部署Szurubooru圖像分享平臺
- 1.1 Szurubooru簡介
- 1.2 主要特點
- 1.3 主要使用場景
- 2.1 本地環(huán)境規(guī)劃
- 2.2 本次實踐介紹
- 3.1 檢查Docker服務(wù)狀態(tài)
- 3.2 檢查Docker版本
- 3.3 檢查docker compose 版本
- 5.1 創(chuàng)建部署目錄
- 5.2 編輯config.yaml文件
- 5.3 編輯.env文件
- 5.4 編輯部署文件
- 5.5 創(chuàng)建Szurubooru容器
- 5.6 查看Szurubooru容器狀態(tài)
- 5.7 查Szurubooru容器日志
- 6.1 訪問Szurubooru初始頁
- 6.2 注冊賬號
- 6.3 上傳圖片
一、Szurubooru介紹
1.1 Szurubooru簡介
Szurubooru
提供了一個強大而靈活的平臺,讓社區(qū)成員可以上傳、分享、討論以及管理多媒體內(nèi)容。它支持多種媒體格式,并提供了一系列工具來幫助用戶組織和發(fā)現(xiàn)內(nèi)容。該平臺特別適合那些需要高度定制化和控制自己內(nèi)容存儲與展示方式的小眾愛好者群體。
1.2 主要特點
- 發(fā)布內(nèi)容:支持圖片(JPG, PNG, GIF, 動態(tài)GIF)、視頻(MP4, WEBM)及Flash動畫。
- 網(wǎng)絡(luò)視頻抓取:能夠使用 yt-dlp 工具從互聯(lián)網(wǎng)上獲取視頻內(nèi)容。
- 評論功能:允許用戶對發(fā)布的每項內(nèi)容添加評論。
- 注釋/標注:支持在圖片上添加注釋,包括自定義多邊形區(qū)域。
- REST API:提供豐富的JSON REST API接口,便于開發(fā)者集成。
- 客戶端認證:基于令牌的認證機制保障了客戶端的安全訪問。
- 搜索系統(tǒng):強大的搜索能力,可以根據(jù)標簽等信息快速找到相關(guān)內(nèi)容。
- 權(quán)限系統(tǒng):精細的權(quán)限設(shè)置確保了不同角色用戶對內(nèi)容的不同訪問級別。
- 自動補全:在搜索或編輯標簽時提供智能提示。
- 標簽分類:支持對標簽進行分組歸類。
- 標簽建議:根據(jù)上下文給出可能相關(guān)的標簽推薦。
- 標簽關(guān)聯(lián):當添加某個標簽時自動關(guān)聯(lián)其他相關(guān)標簽。
- 標簽別名:允許設(shè)定標簽別名以提高查找效率。
- 集合及其類別:方便地將相似主題的內(nèi)容組織成集合并分類。
- 重復檢測:自動識別并標記出潛在的重復內(nèi)容。
- 評分與收藏:用戶可以對自己喜歡的內(nèi)容打分或?qū)⑺鼈兗尤雮€人收藏夾。
- 用戶界面:擁有精致美觀的操作界面。
- 瀏覽器配置選項:支持無盡滾動瀏覽模式及透明圖片背景網(wǎng)格設(shè)置。
1.3 主要使用場景
- 興趣小組:適合動漫迷、藝術(shù)家、攝影師等特定興趣愛好的小圈子使用,作為交流與分享作品的空間。
- 教育用途:教師可以利用此平臺收集教學資源,學生則可以通過瀏覽學習到更多知識。
- 私人收藏:對于想要建立自己的數(shù)字藏品庫的人來說,這是一個非常好的解決方案,無論是藝術(shù)品還是珍貴照片都可以妥善保存并輕松檢索。
- 研究項目:研究人員可借助 Szurubooru 來管理和分析大量視覺資料,比如歷史檔案、科學圖像等。
- 企業(yè)內(nèi)部:公司內(nèi)部也可以部署這樣一個系統(tǒng)用來存放產(chǎn)品圖片、廣告素材等商業(yè)資料,并且通過嚴格的權(quán)限控制保證信息安全。
二、本次實踐規(guī)劃
2.1 本地環(huán)境規(guī)劃
本次實踐為個人測試環(huán)境,操作系統(tǒng)版本為|Ubuntu 22.04.1。
hostname IP地址 操作系統(tǒng)版本 內(nèi)核版本 Docker版本 鏡像版本 jeven01 192.168.3.88 Ubuntu 22.04.1 LTS 5.15.0-119-generic 24.0.7 2.5
2.2 本次實踐介紹
1.本次實踐部署環(huán)境為個人測試環(huán)境,生產(chǎn)環(huán)境請謹慎; 2.在Docker環(huán)境下部署Szurubooru圖像板應(yīng)用。
三、本地環(huán)境檢查
3.1 檢查Docker服務(wù)狀態(tài)
檢查Docker服務(wù)是否正常運行,確保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 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應(yīng)用
5.1 創(chuàng)建部署目錄
- 創(chuàng)建部署目錄
mkdir -p /data/szurubooru && cd /data/szurubooru
- 設(shè)置目錄權(quán)限
chmod -R 777 /data/szurubooru/
5.2 編輯config.yaml文件
編輯config.yaml配置文件,內(nèi)容所轄:
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`目錄下,創(chuàng)建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 創(chuàng)建Szurubooru容器
執(zhí)行以下命令,創(chuàng)建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容器狀態(tài)
檢查Szurubooru容器狀態(tài)狀態(tài),確保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服務(wù)正常運行。
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服務(wù)
6.1 訪問Szurubooru初始頁
訪問地址:http://192.168.3.88:8080,將IP替換為自己服務(wù)器IP地址。如果無法訪問到以下頁面,則檢查宿主機的防火墻是否關(guān)閉或者放行相關(guān)端口,云服務(wù)器則還需要設(shè)置安全組規(guī)則。
6.2 注冊賬號
入下圖所示,在菜單欄點擊“
Register
”選項,注冊賬號。
自定義填寫賬號相關(guān)信息,確認注冊即可。
6.3 上傳圖片
- 上傳本地圖片
- 預(yù)覽圖片效果
七、總結(jié)
在本次Docker項目實戰(zhàn)中,我們成功運用Docker容器化技術(shù)部署了Szurubooru圖像板應(yīng)用,不僅實現(xiàn)了快速搭建和環(huán)境隔離,還顯著提升了工作效率。通過Docker進行部署極大縮短了準備時間,同時保證了Szurubooru能夠在多種環(huán)境中穩(wěn)定運行。這一過程簡化了應(yīng)用的配置與管理,為開發(fā)者提供了極大的便利。鑒于其簡便性和實用性,推薦對圖像板感興趣的朋友嘗試使用Docker來部署Szurubooru。
作者聲明本文無利益相關(guān),歡迎值友理性交流,和諧討論~
,