[新服务] docker-compose calibre-web ebook reader online
date
Feb 16, 2023
slug
newservice-calibre-web-ebook-reader
status
Published
summary
新服务 电子书阅读 自建服务
tags
service
type
Post
URL
Summary
- ‣
步骤
#1
export DOCKER_PROJ=calibre-web
mkdir /data/$DOCKER_PROJ; cd /data/$DOCKER_PROJ
mkdir books
# need to download fresh metadata.db
wget https://1024.ee/wp-content/uploads/2020/08/metadata.db -O ./books/metadata.db
ln -s /drive/qh13_webdav_remote/book ./books/qh13-book
# chown -R www:www books # only needed running with PUID/PGID=1000
cat > docker-compose.yml <<EOF
---
version: "2.1"
services:
calibre-web:
image: lscr.io/linuxserver/calibre-web:latest
container_name: calibre-web
environment:
- PUID=0
- PGID=0
# - TZ=Etc/UTC
- TZ=Asia/Hong_Kong
- DOCKER_MODS=linuxserver/mods:universal-calibre #optional
- OAUTHLIB_RELAX_TOKEN_SCOPE=1 #optional
volumes:
- ./config:/config
- ./books:/books
- ./books/qh13-book:/books/qh13-book
# ports:
# - 8083:8083
restart: unless-stopped
networks:
default:
name: npm_nginx_proxy_manager-network
external: true
EOF
docker-compose down; docker-compose up -d; sleep 1s; docker-compose logs -f
docker-compose pull
docker-compose up -d # 请不要使用docker-compose stop来停止容器,因为这么做需要额外的时间等待容器停止;docker-compose up -d直接升级容器时会自动停止并立刻重建新的容器,完全没有必要浪费那些时间。
docker image prune # prune 命令用来删除不再使用的 docker 对象。删除所有未被 tag 标记和未被容器使用的镜像
#2批量加入和删除书籍
docker exec -it calibre-web bash
cd /books
# 先备份metadata.db
cp metadata.db metadata_$(date +'%Y_%m_%d_%H_%M').db
# 假设待加入的书在 /books/_new2add
calibredb add --library-path=/books -r /books/qh13-book
# 一旦出错,这样既可
cp metadata_backupdate_time.db metadata.db
exit
docker restart calibre-web
# 把书列出来
calibredb list --library-path=/books
# 删除书,ids是一个id或者逗号分隔的多个id
calibredb remove --library-path=/books ids
# 搜索书籍,会列出id
calibredb search --library-path=/books python
#3 cron job to add new books
/usr/bin/docker exec -it calibre-web /bin/bash -c "cp /books/metadata.db /books/bak/metadata_$(date +'%Y_%m_%d_%H_%M').db && calibredb add --library-path=/books -r /books/_new2add/; rm -rf /books/_new2add/*"
/usr/bin/docker exec -it calibre-web /bin/bash -c "cp /books/metadata.db /books/_bak/metadata_$(date +'%Y_%m_%d_%H_%M').db && calibredb add --library-path=/books -r /add-n-delete/qh13-book-calibre_central_add-n-delete; calibredb add --library-path=/books -r /add-n-delete/gd_stanford-_host-calibre-web-add-n-delete"
#4 reverse proxy
location / {
proxy_pass http://calibre-web:8083/; # 注意改成你实际使用的端口
rewrite ^/(.*)$ /$1 break;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade-Insecure-Requests 1;
proxy_set_header X-Forwarded-Proto https;
}
other settings
/usr/bin/ebook-convert
/usr/bin/kepubify
/usr/bin/unrar
解决db的另外一种方法
docker exec -it calibre-web sh #进入容器内部
cd /app/calibre/bin #进入bin文件夹
calibredb restore_database --really-do-it --with-library /books #创建一个数据库
chmod a+w /books/metadata.db #添加写的权限
exit # 退出容器