Skip to content

Instantly share code, notes, and snippets.

@davidwu111
Last active October 4, 2023 11:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwu111/b8d7d28355a6dd92147033428ce4e29e to your computer and use it in GitHub Desktop.
Save davidwu111/b8d7d28355a6dd92147033428ce4e29e to your computer and use it in GitHub Desktop.
Cloudreve Docker-compose Sample
# Required
# > PUID & PGID
CLOUDREVE_PUID=0
CLOUDREVE_PGID=0
# > Aria2
ARIA2_RPC_SECRET=&1%2Kdf3%piY$
# Optional
# But I highly recommend you keep items below as default
# unless you know what you are doing.
# > Temp download folder for Aria2 & Cloudreve
TEMP_FOLDER_PATH={CLOUDREVE_PATH}/dockercnf/aria2/temp
# > Aria2
ARIA2_CONFIG_PATH={CLOUDREVE_PATH}/dockercnf/aria2/conf
# > Cloudreve
CLOUDREVE_UPLOAD_PATH={CLOUDREVE_PATH}/sharedfolders
CLOUDREVE_CONF_PATH={CLOUDREVE_PATH}/dockercnf/cloudreve/config
CLOUDREVE_DB_PATH={CLOUDREVE_PATH}/dockercnf/cloudreve/db
CLOUDREVE_AVATAR_PATH={CLOUDREVE_PATH}/dockercnf/cloudreve/avatar

昨天在我的Azure空闲虚拟机上部署了一个Cloudreve跟小伙伴们分享视频,跟着官方文档用Docker-compose,并且改用Caddy实现https证书自动续期和反代,比nginx要再方便一点。搜了一下好像没有类似的做法,发出来供大家参考。


1. 事先准备

  1. Linux 安装 docker-compose 请自己搜索,非常非常多的教程, 也可以参考官方教程先安装好docker, 再sudo apt install docker-compose 即可。官方教程 https://docs.docker.com/engine/install/ubuntu/
  2. 使用的 docker 镜像地址 https://hub.docker.com/r/xavierniu/cloudreve
  3. 确定好你的Cloudreve 根目录,该挂载存储之类的先行做好。例如我的Cloudreve根目录是 /home/wu/cloudreve 文件夹,这是我从Azure Storage 远程挂载过来的目录。常见的比如挂载第二块虚拟磁盘或硬盘后,先设置好fstab以防重启后目录出问题。
  4. 给虚拟机IP指定好域名的解析。

2. 开始部署

  1. 创建 .env 文件设置环境变量,示例文件放在附件了。 这里需要改的地方第一个是获取PUID & PGID。这是你运行Docker的用户,一般新部署的docker环境就默认是root用户,获得root用户ID的命令是 id root 将获得的ID写入 .env 文件里,root一般都是0 (毕竟是系统里最大的大佬用户)
  2. 在 .env 文件里,更改 aria2的token,自己可以瞎写一串,但是要记下来配置里用得到。
  3. 在 .env 文件里,将{CLOUDREVE_PATH}更改为你的 Cloudreve根目录。
  4. 创建 Caddyfile,直接用附件的不需要改。
  5. 创建 docker-compose.yml 需要改的是16行你的域名,17行你的邮箱地址(用在HTTPS证书申请),其他的可以不用动。
  6. 创建Cloudreve的 conf.ini 内容非常简单,默认使用内置的SQLite数据库即可,如果要用其他数据库请参考官方文档修改这个文件内容。将这个文件放在{CLOUDREVE_PATH}/dockercnf/aria2/conf 这个文件夹下。(文件夹不存在可以创建好)

3. 启动!

除了conf.ini,其它的3个文件放在同一个文件夹里。输入命令 sudo docker-compose up -d 此时docker会自动拉取image并且启动三个容器。稍等片刻后看到三个done就是容器启动成功。 使用以下命令查看docker 容器运行状态 sudo docker ps [upl-image-preview url=https://forum.cloudreve.org/assets/files/2021-09-20/1632150068-428714-screenshot-2021-09-20-230048.jpeg] 图中的status下面看到up则是正常运行。图中第一列container id是你启动容器的id,例如我这里cloudreve的容器id是a78f08fe2f1b 使用以下命令查看Cloudreve的初始log,获取默认管理员账户和密码 (将后面的id a78f08fe2f1b 改为你的id) sudo docker logs a78f08fe2f1b 此时你应该可以通过域名直接访问并且用管理员账户登录做各种设置了!


4. 维护

  1. 如果你的服务器直接暴露在公网,建议设置好防火墙规则,只允许80,443,22这些常用端口。特别是云服务器的IP段经常被扫描。
  2. 安装fail2ban防止密码爆破,例如它的默认设置会使SSH密码输错的IP,被禁用10分钟,输入命令安装即可 sudo apt install fail2ban
  3. 常用的docker命令最好学习下,非常简单, 这样在维护的时候会方便很多,例如: docker start docker stop docker ps docker rm
  4. 备份。因为我们用的是SQlite所以非常简单粗暴,直接把根目录压缩存起来就行。

用到的文件不支持传在附件中, 我放在github上了。

{$DOMAIN}:443 {
log {
level INFO
output file {$LOG_FILE} {
roll_size 10MB
roll_keep 10
}
}
# Use the ACME HTTP-01 challenge to get a cert for the configured domain.
tls {$EMAIL}
# This setting may have compatibility issues with some browsers
# (e.g., attachment downloading on Firefox). Try disabling this
# if you encounter issues.
encode gzip
# Notifications redirected to the WebSocket server
reverse_proxy /notifications/hub cloudreve:3012
# Proxy everything else to Rocket
reverse_proxy cloudreve:5212 {
# Send the true remote IP to Rocket, so that fail2ban can ban the correct IP.
header_up X-Real-IP {remote_host}
}
}
# conf.ini
[Database]
DBFile = /cloudreve/db/cloudreve.db
version: '3'
services:
caddy:
image: caddy:2
container_name: caddy
restart: unless-stopped
ports:
- 80:80 # Needed for the ACME HTTP-01 challenge.
- 443:443
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- ./caddy-config:/config
- ./caddy-data:/data
environment:
- DOMAIN=https://your.domain.com # Your domain, prefixed with http or https.
- EMAIL=youremail@email.com # The email address to use for ACME registration.
- LOG_FILE=/data/access.log
networks:
- cloudreve-network
aria2:
image: p3terx/aria2-pro
logging:
options:
max-size: 1m
ports:
- 6800:6800
- 6888:6888
- 6888:6888/udp
environment:
- PUID=${CLOUDREVE_PUID}
- PGID=${CLOUDREVE_PGID}
- RPC_SECRET=${ARIA2_RPC_SECRET}
volumes:
- ${ARIA2_CONFIG_PATH}:/config
- ${TEMP_FOLDER_PATH}:/downloads
networks:
- cloudreve-network
restart: unless-stopped
cloudreve:
image: xavierniu/cloudreve
environment:
- PUID=${CLOUDREVE_PUID}
- PGID=${CLOUDREVE_PGID}
volumes:
- ${CLOUDREVE_UPLOAD_PATH}:/cloudreve/uploads
- ${TEMP_FOLDER_PATH}:/downloads
- ${CLOUDREVE_CONF_PATH}:/cloudreve/config
- ${CLOUDREVE_DB_PATH}:/cloudreve/db
- ${CLOUDREVE_AVATAR_PATH}:/cloudreve/avatar
networks:
- cloudreve-network
networks:
cloudreve-network:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment